Skip to content

Add CLI args and __main__ guard to final.py (part of #10) - #12

Open
abhishekKokadwar wants to merge 1 commit into
RedHenLab:mainfrom
abhishekKokadwar:fix/final-py-cli-args
Open

abhishekKokadwar wants to merge 1 commit into
RedHenLab:mainfrom
abhishekKokadwar:fix/final-py-cli-args

Conversation

@abhishekKokadwar

Copy link
Copy Markdown

Addresses the two remaining items from #10 (the IndexError is fixed separately in #11).

Bug

final.py hardcoded its input/output filenames (annotated_pos_sent.txt, output.vrt) and ran all its logic, including file I/O, at import time with no if __name__ == "__main__": guard. This is inconsistent with every other script in english/ and farsi/ (e.g. convert_to_xml.py uses argparse), breaks the batch pipeline usage described in Farsi_readme.md step 5 (which expects arbitrary file paths), and means the script can't be imported/unit-tested without side effects.

Fix

  • Added argparse with -i/--input and -o/--output, using the previous hardcoded names as defaults so existing usage (python final.py with no args, from a directory containing annotated_pos_sent.txt) still works unchanged.
  • Wrapped the processing logic in main(input_file, output_file) behind an if __name__ == "__main__": guard.

Note on overlap with #11

This branch was cut from main (not from #11's branch), so it also carries forward the len(parts) < 10 guard fix from #11 to keep the file consistent — otherwise this PR would silently regress that fix. If #11 merges first, this will need a trivial rebase (the only overlap is that one line + a whitespace nit); happy to do that once #11 is in.

Testing

Added farsi/test_final.py, which imports the module directly (safe now that there's no import-time I/O) and checks:

$ python test_final.py
all tests passed
$ python final.py --help
usage: final.py [-h] [-i INPUT] [-o OUTPUT]
...

final.py previously hardcoded its input/output filenames
(annotated_pos_sent.txt, output.vrt) and ran file I/O at import time,
inconsistent with every other script in the repo. Added argparse with
the same filenames as defaults (backward compatible) and wrapped the
logic in main() behind an if __name__ == "__main__" guard, so the
module can be imported and unit-tested without side effects.

Also carries forward the len(parts) < 10 fix from RedHenLab#11, since this PR
branches from main rather than that fix's branch.

Addresses the remaining two items from RedHenLab#10; the IndexError fix is in RedHenLab#11.
Copilot AI lite review requested due to automatic review settings September 1, 2026 13:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Farsi pipeline’s final.py script to behave like a proper CLI tool (rather than executing file I/O at import time), enabling batch/pipeline usage with arbitrary input/output paths and making the module safe to import for testing.

Changes:

  • Added argparse (-i/--input, -o/--output) with defaults matching the prior hardcoded filenames.
  • Moved processing and file I/O into main(input_file, output_file) and added an if __name__ == "__main__": guard.
  • Added a self-check test script that imports final and verifies both the short-line regression and path-based I/O.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
farsi/final.py Adds CLI args and __main__ guard; wraps processing in main() while preserving existing defaults.
farsi/test_final.py Adds a self-check that imports final and validates short-line handling + custom input/output paths.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread farsi/final.py
Comment on lines 4 to 6
def convert_dependency_tree(vrt_content):
result = []
for line in vrt_content.strip().split('\n'):
Comment thread farsi/final.py


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Post-process a UDPipe-annotated CONLL-U file into .fa.txt format.")
Comment thread farsi/test_final.py
Comment on lines +1 to +2
# Self-check for final.py.
# Run directly: python test_final.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants