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

Explicitly pass filter to TarFile.extractall on Python >=3.12 #458

Merged
merged 4 commits into from
Jan 24, 2025

Conversation

drammock
Copy link
Contributor

python 3.13 warns loudly about calling TarFile.extractall without specifying the filter param:

[...EARLIER STEPS OF TRACEBACK OMITTED FOR BREVITY...]
    pooch.retrieve(
/opt/mambaforge/envs/mnedev/lib/python3.13/site-packages/pooch/core.py:251: in retrieve
    return processor(str(full_path), action, None)
/opt/mambaforge/envs/mnedev/lib/python3.13/site-packages/pooch/processors.py:121: in __call__
    self._extract_file(fname, self.extract_dir)
/opt/mambaforge/envs/mnedev/lib/python3.13/site-packages/pooch/processors.py:262: in _extract_file
    tar_file.extractall(path=extract_dir)
/opt/mambaforge/envs/mnedev/lib/python3.13/tarfile.py:2321: in extractall
    filter_function = self._get_filter_function(filter)
/opt/mambaforge/envs/mnedev/lib/python3.13/tarfile.py:2286: in _get_filter_function
    warnings.warn(
E   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.

This PR passes explicitly what will become the default in Py3.14. Honestly I'm surprised this warning wasn't causing test failures in your CIs, but on cursory glance I don't spot any obvious culprit (like a filterwarnings in conftest.py or in [pytest.ini_options] of pyproject.toml, or something similar).

Relevant issues/PRs:

@santisoler
Copy link
Member

Thanks @drammock for this! Nice catch!

Our tests are catching the warning, but they are not raising an error. See for example: https://github.com/fatiando/pooch/actions/runs/12638921221/job/35216179298#step:13:196

[...]
tests/test_processors.py::test_unpacking[Untar-archive_all-default_path]
tests/test_processors.py::test_unpacking[Untar-archive_all-custom_path]
tests/test_processors.py::test_unpacking_members_then_no_members[Untar-.tar.gz]
tests/test_processors.py::test_unpacking_wrong_members_then_no_members[Untar-.tar.gz]
  /opt/hostedtoolcache/Python/3.13.1/x64/lib/python3.13/site-packages/pooch/processors.py:262: 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.
    tar_file.extractall(path=extract_dir)
[...]

I'll open an issue to remind me to add some filterwarnings for our tests.

I'm merging this!

@santisoler santisoler changed the title explicitly pass filter to TarFile.extractall Explicitly pass filter to TarFile.extractall on Python >=3.12 Jan 24, 2025
@santisoler santisoler merged commit f6cbd82 into fatiando:main Jan 24, 2025
18 checks passed
@drammock drammock deleted the extractall-filter branch January 27, 2025 22:33
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