-
Notifications
You must be signed in to change notification settings - Fork 21
fre app regrid edits for fre-workflows functionality
#669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…acy behavior to be fulfilled
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #669 +/- ##
==========================================
+ Coverage 84.98% 85.09% +0.11%
==========================================
Files 68 68
Lines 4523 4597 +74
==========================================
+ Hits 3844 3912 +68
- Misses 679 685 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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 enhances the fre app regrid functionality to support fre-workflows by adding extensive logging, modifying function signatures to support absolute paths, implementing a workaround for legacy fre-nctools behavior, and improving code formatting and documentation.
- Adds comprehensive debug and info logging throughout the regridding workflow
- Modifies
get_input_file()to accept aninput_dirparameter and return absolute paths - Implements a symlink workaround for legacy fre-nctools datetime requirements
- Refactors test code with proper formatting, docstrings, and PEP 8 compliance
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| fre/app/regrid_xy/regrid_xy.py | Adds extensive logging, modifies function signatures for absolute paths, implements legacy fre-nctools symlink workaround, updates fregrid command construction |
| fre/app/regrid_xy/tests/test_regrid_xy.py | Reorganizes imports per PEP 8, adds docstrings to test functions, updates tests to pass input_dir parameter, improves formatting |
| fre/app/regrid_xy/tests/generate_files.py | Adds module docstring, reformats code with proper indentation, adds docstrings to all functions, improves PEP 8 compliance |
Comments suppressed due to low confidence (1)
fre/app/regrid_xy/regrid_xy.py:108
- 'except' clause does nothing but pass and there is no explanatory comment.
except FileExistsError:
| # what in the ever loving demon magic is going on here??? | ||
| try: | ||
| grid_spec_dt_symlink.symlink_to(Path(grid_spec)) | ||
| except FileExistsError: | ||
| pass | ||
|
|
||
| # i am sorry python gods, i have failed out | ||
| if grid_spec_dt_symlink.exists(): | ||
| fre_logger.warning('great? how did this happen?') | ||
|
|
||
| # continued inexplicable success. | ||
| if grid_spec_dt_symlink.is_symlink(): | ||
| fre_logger.warning('symlink created: %s', grid_spec_dt_symlink) | ||
| else: | ||
| raise Exception('problem with accounting for legacy fregrid/fre-nctools behavior, symbolic link creation ' | ||
| 'as-intended-side-effect failed. consult life choices.') | ||
|
|
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comments "what in the ever loving demon magic is going on here???", "i am sorry python gods, i have failed out", "great? how did this happen?", and "continued inexplicable success" are unprofessional and unclear. These should be replaced with technical explanations of the symlink behavior or removed if the code is working as intended. Additionally, the exception message "consult life choices" is inappropriate for production code.
| # what in the ever loving demon magic is going on here??? | |
| try: | |
| grid_spec_dt_symlink.symlink_to(Path(grid_spec)) | |
| except FileExistsError: | |
| pass | |
| # i am sorry python gods, i have failed out | |
| if grid_spec_dt_symlink.exists(): | |
| fre_logger.warning('great? how did this happen?') | |
| # continued inexplicable success. | |
| if grid_spec_dt_symlink.is_symlink(): | |
| fre_logger.warning('symlink created: %s', grid_spec_dt_symlink) | |
| else: | |
| raise Exception('problem with accounting for legacy fregrid/fre-nctools behavior, symbolic link creation ' | |
| 'as-intended-side-effect failed. consult life choices.') | |
| # Attempt to create a symbolic link for legacy fre-nctools compatibility. | |
| try: | |
| grid_spec_dt_symlink.symlink_to(Path(grid_spec)) | |
| except FileExistsError: | |
| # Symlink already exists; proceed. | |
| pass | |
| # Check if the symlink exists after attempted creation. | |
| if grid_spec_dt_symlink.exists(): | |
| fre_logger.warning('Symlink exists: %s', grid_spec_dt_symlink) | |
| # Confirm that the symlink was created successfully. | |
| if grid_spec_dt_symlink.is_symlink(): | |
| fre_logger.warning('Symlink created: %s', grid_spec_dt_symlink) | |
| else: | |
| raise Exception( | |
| 'Failed to create symbolic link for legacy fregrid/fre-nctools behavior. ' | |
| 'Symbolic link creation did not succeed. Please check file permissions and whether the symlink already exists.' | |
| ) |
| for source in component["sources"]: | ||
| history_file = source["history_file"] | ||
| for i in range(1, ntiles+1): | ||
| #print(f"input_dir is {input_dir}") # input dir is /home/Ian.Laflotte/Working/fre-cli/test_inputs |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out debug print statement should be removed. Leftover debug code should not remain in the codebase.
| #print(f"input_dir is {input_dir}") # input dir is /home/Ian.Laflotte/Working/fre-cli/test_inputs |
|
|
||
| ppyaml = {} | ||
| ppyaml["name"] = yamlfile | ||
| ppyaml= {} |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent spacing around assignment operator. Should be ppyaml = {} instead of ppyaml= {}.
| ppyaml= {} | |
| ppyaml = {} |
|
|
||
| generate_files.make_grid_spec() | ||
| mosaic_file.touch() | ||
| datadict=dict(grid_spec=grid_spec, inputRealm="ocean") |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after assignment operator. Should be datadict = dict(...) instead of datadict=dict(...).
| datadict=dict(grid_spec=grid_spec, inputRealm="ocean") | |
| datadict = dict(grid_spec=grid_spec, inputRealm="ocean") |
| fre_logger.debug('checking if %s is a tar file...', pp_grid_spec_tar) | ||
| if tarfile.is_tarfile(pp_grid_spec_tar): | ||
|
|
||
| fre_logger.debug('it is a tar file! attempting top open %s', pp_grid_spec_tar) |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "attempting top open" should be "attempting to open".
| fre_logger.debug('it is a tar file! attempting top open %s', pp_grid_spec_tar) | |
| fre_logger.debug('it is a tar file! attempting to open %s', pp_grid_spec_tar) |
| :type datadict: dict | ||
| :param source: history file type | ||
| :type source: str | ||
| :param input_dir: input file directory |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing type annotation for the newly added input_dir parameter. The docstring documents it but the function signature should include : str type hint for consistency with other parameters.
| # assert False | ||
|
|
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out assertion # assert False should be removed. Commented-out debug code should not be left in production code.
| # assert False |
| with tarfile.open(pp_grid_spec_tar, "r") as tar: | ||
|
|
||
| fre_logger.debug('opened! about to extract all from opened tar file object into %s', os.getcwd()) | ||
| tar.extractall() |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using tar.extractall() without a filter is unsafe as it can lead to path traversal attacks. Consider using tar.extractall(filter='data') (Python 3.12+) or validate member paths before extraction to prevent malicious tar archives from writing files outside the intended directory.
| datadict["input_date"] = input_date[:8] | ||
| fre_logger.info( 'datadict is %s', pprint.pformat(datadict) ) | ||
|
|
||
| datadict["grid_spec"], grid_spec_symlink = get_grid_spec(datadict) |
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable grid_spec_symlink is not used.
| datadict["grid_spec"], grid_spec_symlink = get_grid_spec(datadict) | |
| datadict["grid_spec"] = get_grid_spec(datadict)[0] |
No description provided.