Skip to content

Commit

Permalink
Backport PR #2455: feat: Use Python 3.12+ tarfile data extraction filter
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewfeickert authored and meeseeksmachine committed May 30, 2024
1 parent 71b87eb commit c0b9a1b
Showing 1 changed file with 6 additions and 1 deletion.
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 @@ def download(archive_url, output_directory, force=False, compress=False):
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

0 comments on commit c0b9a1b

Please sign in to comment.