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

Filter tar in extract_archive() for Python>=3.12 #163

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Conversation

hagenw
Copy link
Member

@hagenw hagenw commented Nov 27, 2024

In Python 3.12 the filter argument was introduced to TarFile.extract(), see tarfile.TarFile.extract and tarfile-extraction-filter.

When testing with Python 3.13 it raises the following deprecation warning:

.../audeer/core/io.py:374: DeprecationWarning: Python 3.14 will, by default,
filter extracted tar archives and reject files or modify their metadata.
Use the filter argument to control this behavior.

To avoid this, and make it also safe when Python 3.14 is introduced, this pull requests adds filter="tar" when extracting a tar archive in audeer.extract_archive() in Python >=3.12.

Summary by Sourcery

Bug Fixes:

  • Add the 'filter' argument to TarFile.extract() in extract_archive() for Python >=3.12 to prevent deprecation warnings in future Python versions.

sourcery-ai[bot]

This comment was marked as outdated.

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.0%. Comparing base (92e64c6) to head (937013a).
Report is 1 commits behind head on main.

Additional details and impacted files
Files with missing lines Coverage Δ
audeer/core/io.py 100.0% <100.0%> (ø)

@hagenw hagenw changed the title Catch tar deprecation warning in extract_archive() Filter tar in extract_archive() for Python>=3.12 Nov 27, 2024
@audeering audeering deleted a comment from sourcery-ai bot Nov 27, 2024
@hagenw
Copy link
Member Author

hagenw commented Nov 27, 2024

@sourcery-ai review

Copy link

sourcery-ai bot commented Nov 27, 2024

Reviewer's Guide by Sourcery

The PR updates the extract_archive() function to handle the new filter parameter introduced in Python 3.12 for tar file extraction. The implementation uses version checking to conditionally add the filter parameter, ensuring compatibility with Python 3.12+ while maintaining backward compatibility with older versions.

Class diagram for extract_archive() function update

classDiagram
    class ExtractArchive {
        +extract_archive()
    }
    class TarFile {
        +extract(member, destination, numeric_owner=True)
    }
    ExtractArchive --|> TarFile : uses
    note for ExtractArchive "Updated to include filter parameter for Python >= 3.12"
    note for TarFile "Python 3.12 introduces filter argument"
Loading

File-Level Changes

Change Details Files
Added version-specific handling for tar file extraction
  • Created a kwargs dictionary to store extraction parameters
  • Added version check for Python 3.12 and above
  • Conditionally added 'filter="tar"' parameter for Python 3.12+
  • Updated extract call to use kwargs unpacking
audeer/core/io.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @hagenw - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@hagenw hagenw requested a review from ChristianGeng November 27, 2024 08:37
@ChristianGeng ChristianGeng self-requested a review November 27, 2024 09:51
Copy link
Member

@ChristianGeng ChristianGeng left a comment

Choose a reason for hiding this comment

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

The version-specific choice of a sane default for the filter argument has been discussed in a separate thread that is settled now.

Therefore it feels safe to approve right now.

@hagenw hagenw merged commit b438c9e into main Nov 27, 2024
22 checks passed
@hagenw hagenw deleted the tar-deprecation branch November 27, 2024 09:54
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.

2 participants