Use argparse in plain_bpmf_compiler - #762
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors plain_bpmf_compiler.py to use argparse for command-line argument parsing, which improves the script's usability and clarity. The core logic has been moved into a cook function, separating it from the argument parsing. My main feedback is regarding resource management: the script opens files without ensuring they are closed, which can lead to resource leaks. Using with statements for file handling is the recommended practice to avoid this.
There was a problem hiding this comment.
Pull request overview
This PR refactors plain_bpmf_compiler.py to use argparse for command-line argument handling, aligning it with the pattern already established in main_compiler.py. The refactoring improves maintainability by separating the business logic into a cook() function and using modern argument parsing instead of manual sys.argv handling.
- Refactored command-line parsing from manual
sys.argvaccess to argparse with named arguments - Extracted compilation logic into a
cook()function that accepts file paths as parameters - Updated the Makefile invocation to use the new named argument format
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| Source/Data/curation/compilers/plain_bpmf_compiler.py | Refactored to use argparse with named arguments and extracted a cook() function, following the pattern from main_compiler.py |
| Source/Data/Makefile | Updated the plain_bpmf_compiler invocation to use named arguments matching the new argparse interface |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors plain_bpmf_compiler.py to use argparse and with statements, which are great improvements for robustness and readability. The logic is also nicely split into cook and main functions. My review includes one high-severity suggestion to address a memory-efficiency regression introduced when reading one of the input files, ensuring the script remains performant even with large datasets.
a455044 to
268ac56
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request is a nice refactoring of the plain_bpmf_compiler.py script. Using argparse for command-line arguments is a significant improvement in usability and clarity over direct sys.argv access. The separation of the main logic into a cook function and the use of with statements for file handling make the code more robust and Pythonic. The corresponding changes in the Makefile are also correct. I've identified a significant portability issue where file encodings are not specified, which could cause the script to fail on different operating systems. I've added comments with suggestions to address this. Overall, this is a valuable improvement to the codebase.
|
Look good. Thanks! |
A small PR to continue the work of refactoring the curation (phrase database compiler) code. Also using this to test how much my previous PRs have tuned the automated code review comments.