Skip to content
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

Refactor reference file loading #233

Merged
merged 16 commits into from
Dec 16, 2024
Merged

Refactor reference file loading #233

merged 16 commits into from
Dec 16, 2024

Conversation

hpparvi
Copy link
Contributor

@hpparvi hpparvi commented Nov 18, 2024

This PR addresses Issue #169 (also discussed in PR #165) by using the astropy.config.ConfigNamespace.set_temp context manager to temporarily set the default data download URL and then using either astropy.utils.data.get_pkg_data_fileobj or astropy.utils.data.get_pkg_data_filename to get a readable file or a path to the downloaded and cached file.

However, I'm not convinced this approach leads to more elegant code than the original one. We eliminate the two wrapper functions, but the file-handling code is somewhat messy because of all the nesting. Please take a look and let me know what you think.

…eobj and get_pkg_data_filename and translate URLError errors into warnings.
Copy link

codecov bot commented Nov 18, 2024

Codecov Report

Attention: Patch coverage is 92.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84.77%. Comparing base (ef38dc0) to head (9aecda5).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
specreduce/calibration_data.py 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #233      +/-   ##
==========================================
+ Coverage   83.36%   84.77%   +1.41%     
==========================================
  Files          13       13              
  Lines        1136     1123      -13     
==========================================
+ Hits          947      952       +5     
+ Misses        189      171      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hpparvi hpparvi changed the title Issue 169 fix Refactor reference file loading Nov 18, 2024
@hpparvi
Copy link
Contributor Author

hpparvi commented Nov 27, 2024

Do you have any opinions about this, @cshanahan1, @tepickering, and @kecnry? If nobody opposes this approach, I'll improve the code coverage and see if I can make the code a bit more readable.

@tepickering
Copy link
Contributor

thanks for catching this! i filed the original issue, but had long since forgotten about it 😅. i like what you've done so far. will give it a closer look when you're more ready to merge. a few test failures to address as well as the coverage.

…ion_data.

- Marked several of the function arguments used by the previous approach as deprecated (pending) using deprecated_renamed_argument.
- Improved tests to bring calibration_data coverage to 87%.
…raised for "test_make_2d_arc_pass_wcs" and "test_load_onedstds" on Python 3.11.
… find the reason why they happen in Python 3.11 rather than just to ignore them.
…s. This leads to more readable and cleaner code in the end.

- Changed the cache type hints to "bool | Literal['update']"
…Python 3.11 for tests that tried to download a nonexistent file even when the URLError was caught correctly.
@hpparvi
Copy link
Contributor Author

hpparvi commented Dec 3, 2024

Thanks, @tepickering. However, the more I looked at the approach, the less I liked it. The code's readability decreased too much without any improvements in the functionality. I've now switched back to using download_file consistently but without the wrappers (and added a couple of new tests checking that we catch URLErrors from bad file names correctly), which leads to cleaner and more readable code.

The PR is ready to merge in theory, but the code doesn't differ much from the original. It mainly just skips the use of the download wrapper functions. If you still think this is worth merging, doing a squash merge is probably best because most of the intermediate commits were very small.

Copy link
Contributor

@tepickering tepickering left a comment

Choose a reason for hiding this comment

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

looks good. my only comment of note is that some of the diffs are due to changes in code style. it may be worth following what astropy does and use black and/or ruff to define the style and apply it automatically and consistently.

@tepickering
Copy link
Contributor

Thanks, @tepickering. However, the more I looked at the approach, the less I liked it. The code's readability decreased too much without any improvements in the functionality. I've now switched back to using download_file consistently but without the wrappers (and added a couple of new tests checking that we catch URLErrors from bad file names correctly), which leads to cleaner and more readable code.

The PR is ready to merge in theory, but the code doesn't differ much from the original. It mainly just skips the use of the download wrapper functions. If you still think this is worth merging, doing a squash merge is probably best because most of the intermediate commits were very small.

it might, in fact, be worthwhile to make squash merging the default going forward. right now all three methods are allowed and i can't see how to change the default to "squash". i think it becomes the default if i disable "merge commit", but not sure if we want to pull that trigger yet. i'm fine with keeping our options open and deciding on a per-PR basis, but i'm open to other ideas.

@hpparvi hpparvi merged commit fe130ab into astropy:main Dec 16, 2024
20 of 21 checks passed
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