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

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Mar 13, 2024

Description

Resolves #2454

In Python 3.12 extraction filters are added and will become default in Python 3.14. To start using them for when Python 3.12 support is added, and to guard against a Python 3.14 DeprecationWarning, use the data extraction filter for extracting tarfiles in pyhf.contrib.utils.download.

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* In Python 3.12 extraction filters are added and will become default in
  Python 3.14. To start using them for when Python 3.12 support is added, and
  to guard against a Python 3.14 DeprecationWarning, use the data extraction
  filter for extracting tarfiles in pyhf.contrib.utils.download.
   - c.f. https://docs.python.org/3.12/library/tarfile.html#extraction-filters

* In Python 3.12 extraction filters are added and in will become default in
  Python 3.14. To start using them for when Python 3.12 support is added, and
  to guard against a Python 3.14 DeprecatinoWarning, use the data extraction
  filter for extracting tarfiles in pyhf.contrib.utils.download.
   - c.f. https://docs.python.org/3.12/library/tarfile.html#extraction-filters
@matthewfeickert matthewfeickert added feat/enhancement New feature or request fix A bug fix contrib Targeting pyhf.contrib and not the core of pyhf need-to-backport tmp label until can be backported to patch release branch labels Mar 13, 2024
@matthewfeickert matthewfeickert self-assigned this Mar 13, 2024
Comment on lines +94 to +97
# 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")
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.

Copy link

codecov bot commented Mar 13, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 98.23%. Comparing base (adddb07) to head (b2001f7).

Files Patch % Lines
src/pyhf/contrib/utils.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2455      +/-   ##
==========================================
- Coverage   98.28%   98.23%   -0.05%     
==========================================
  Files          69       69              
  Lines        4539     4541       +2     
  Branches      803      804       +1     
==========================================
  Hits         4461     4461              
- Misses         45       46       +1     
- Partials       33       34       +1     
Flag Coverage Δ
contrib 97.81% <33.33%> (-0.05%) ⬇️
doctest 98.10% <33.33%> (-0.05%) ⬇️
unittests-3.10 96.25% <33.33%> (-0.05%) ⬇️
unittests-3.11 96.25% <33.33%> (-0.05%) ⬇️
unittests-3.8 96.27% <33.33%> (-0.05%) ⬇️
unittests-3.9 96.30% <33.33%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@matthewfeickert
Copy link
Member Author

I'm going to approve and merge this myself. As always, PRs approved by a single core dev can be reverted as needed by the rest of the dev team.

@matthewfeickert matthewfeickert merged commit 50f1076 into main Mar 15, 2024
20 of 23 checks passed
@matthewfeickert matthewfeickert deleted the fix/support-py-3-12-tarfile-filter branch March 15, 2024 19:38
@matthewfeickert
Copy link
Member Author

@meeseeksdev backport to release/v0.7.x

meeseeksmachine pushed a commit to meeseeksmachine/pyhf that referenced this pull request May 30, 2024
@matthewfeickert matthewfeickert removed the need-to-backport tmp label until can be backported to patch release branch label May 30, 2024
matthewfeickert added a commit that referenced this pull request May 30, 2024
* Backport PR #2455
* In Python 3.12 extraction filters are added and will become default in
  Python 3.14. To start using them for when Python 3.12 support is added, and
  to guard against a Python 3.14 DeprecationWarning, use the data extraction
  filter for extracting tarfiles in pyhf.contrib.utils.download.
   - c.f. https://docs.python.org/3.12/library/tarfile.html#extraction-filters

Co-authored-by: Matthew Feickert <matthew.feickert@cern.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contrib Targeting pyhf.contrib and not the core of pyhf feat/enhancement New feature or request fix A bug fix
Projects
Status: Done
1 participant