Handle missing uncompresspy in fitsinfo without traceback#19869
Open
mokashang wants to merge 2 commits into
Open
Handle missing uncompresspy in fitsinfo without traceback#19869mokashang wants to merge 2 commits into
mokashang wants to merge 2 commits into
Conversation
When the optional dependency uncompresspy is not installed, running fitsinfo on an LZW-compressed .Z file currently raises an uncaught ModuleNotFoundError and prints a long traceback. Catch ImportError alongside the existing OSError so the user instead sees a clean error message, matching the behaviour of fitsdiff (which already catches this case via FITSDiff.__init__). Includes a regression test that mirrors the existing fitsdiff test by monkeypatching HAS_UNCOMPRESSPY to False and running the script against the bundled lzw.fits.Z data file. Fixes astropy#19852
Contributor
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #19852.
Problem
Running
fitsinfoon an LZW-compressed.Zfile currently crashes with an uncaughtModuleNotFoundErrortraceback when the optionaluncompresspydependency is not installed:fitsinfo.fitsinfo()only catchesOSError, so theModuleNotFoundErrorraised by_BaseHDU._readfrom→_File.__init__→_try_read_compressedpropagates up uncaught.Fix
Broaden the
exceptinfitsinfo()to also catchImportErrorand log a clean error message, matching the behaviour offitsdiff(which already handles this case —FITSDiff.__init__wraps any exception fromfitsopeninOSError, so its existingexcept OSErrorhappens to catch this).After the fix:
Scope
This PR only addresses
fitsinfo. The issue mentions "fitsinfo (and probably fitsdiff too)", but I verifiedfitsdiffalready produces a cleanWarning: failed to open ...message on the same input (covered by the existingtest_warning_unreadable_filetest intest_fitsdiff.py, added in #18882).Testing
test_missing_optional_dependencyinastropy/io/fits/tests/test_fitsinfo.py, modelled on the existingtest_warning_unreadable_fileforfitsdiff. It monkeypatchesHAS_UNCOMPRESSPYtoFalseand asserts that runningfitsinfoonlzw.fits.Zlogs an error mentioninguncompresspyrather than raising.main(with the originalModuleNotFoundErrortraceback) and passes with this fix.astropy/io/fits/tests/suite passes locally (1078 passed, 29 skipped — the skipped tests are the ones that requireuncompresspyto actually be installed).Changelog
Added
docs/changes/io.fits/19852.bugfix.rst. Happy to rename it to the PR number once assigned.