Skip to content

RF: Pull compression detection logic into a central private module #1212

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

Merged
merged 1 commit into from
Mar 11, 2023

Conversation

effigies
Copy link
Member

This change is motivated by a change in pyzstd, which exposes failures to read bad streams as custom ZstdErrors instead of OSErrors. We had previously been depending on a conflation of these, as BZ2File returns a straightforward OSError and GzipFile returns BadGzipFile, which subclasses from OSError.

Now there's no clear way of catching the various ways that reading a stream might fail without creating a collection of exceptions and adding to it when an interface that emits different errors is found.

Therefore, I've created a private nibabel._compression module. This houses openers.COMPRESSED_FILE_LIKES and aliases IndexedGzipFile to GzipFile when it is unavailable, as well as provides a new COMPRESSION_ERRORS exception type tuple that can be used in except statements.

Fixes #1209.

@codecov
Copy link

codecov bot commented Mar 10, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.02 🎉

Comparison is base (3a4cc5e) 92.14% compared to head (f7a90fe) 92.16%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1212      +/-   ##
==========================================
+ Coverage   92.14%   92.16%   +0.02%     
==========================================
  Files          97       98       +1     
  Lines       12334    12340       +6     
  Branches     2534     2535       +1     
==========================================
+ Hits        11365    11373       +8     
+ Misses        647      645       -2     
  Partials      322      322              
Impacted Files Coverage Δ
nibabel/_compression.py 100.00% <100.00%> (ø)
nibabel/filebasedimages.py 97.33% <100.00%> (+0.01%) ⬆️
nibabel/openers.py 92.92% <100.00%> (-0.42%) ⬇️
nibabel/volumeutils.py 93.65% <100.00%> (-0.10%) ⬇️

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@effigies
Copy link
Member Author

No change to the API, and it fixes the failing CI. Happy to discuss alterations after the merge.

@effigies effigies merged commit cafd0ab into nipy:master Mar 11, 2023
@effigies effigies deleted the fix/zstd_error branch March 11, 2023 13:12
@effigies effigies added this to the 5.1.0 milestone Mar 29, 2023
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.

Failing zstd tests
1 participant