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(backport): Use Python 3.12+ tarfile data extraction filter #2500

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
# c.f. https://docs.python.org/3.12/library/tarfile.html#extraction-filters
if hasattr(tarfile, "data_filter"):
archive.extractall(output_directory, filter="data")
else:
archive.extractall(output_directory)

Check warning on line 99 in src/pyhf/contrib/utils.py

View check run for this annotation

Codecov / codecov/patch

src/pyhf/contrib/utils.py#L99

Added line #L99 was not covered by tests
except tarfile.ReadError:
if not zipfile.is_zipfile(BytesIO(response.content)):
raise exceptions.InvalidArchive(
Expand Down
Loading