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

feat: Use Python 3.12+ tarfile data extraction filter #2455

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/pyhf/contrib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@
with tarfile.open(
mode="r:*", fileobj=BytesIO(response.content)
) as archive:
archive.extractall(output_directory)
# TODO: Simplify after pyhf is Python 3.12+ only

Check notice on line 94 in src/pyhf/contrib/utils.py

View check run for this annotation

codefactor.io / CodeFactor

src/pyhf/contrib/utils.py#L94

unresolved comment '# TODO: Simplify after pyhf is Python 3.12+ only' (C100)
# c.f. https://docs.python.org/3.12/library/tarfile.html#extraction-filters
if hasattr(tarfile, "data_filter"):
archive.extractall(output_directory, filter="data")
Comment on lines +94 to +97
Copy link
Member Author

Choose a reason for hiding this comment

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

This won't ever get run in the current tests and so Codecov is going to complain, but is passes on the testing Python 3.12 branch that I have and so will get covered in the future.

else:
archive.extractall(output_directory)
except tarfile.ReadError:
if not zipfile.is_zipfile(BytesIO(response.content)):
raise exceptions.InvalidArchive(
Expand Down
Loading