-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
…elf-written wrappers around download_data.
…eobj and get_pkg_data_filename and translate URLError errors into warnings.
Codecov ReportAttention: Patch coverage is
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. |
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. |
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.
15f5128
to
9aecda5
Compare
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. |
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.
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.
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. |
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 eitherastropy.utils.data.get_pkg_data_fileobj
orastropy.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.