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
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
11 changes: 10 additions & 1 deletion audeer/core/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import itertools
import os
import shutil
import sys
import tarfile
import typing
import urllib.request
Expand Down Expand Up @@ -369,7 +370,15 @@ def extract_archive(
desc=desc,
disable=disable,
):
tf.extract(member, destination, numeric_owner=True)
# In Python 3.12 the `filter` argument was introduced,
ChristianGeng marked this conversation as resolved.
Show resolved Hide resolved
# and it will be set automatically in Python 3.14,
# see
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
# noqa: E501
kwargs = {"numeric_owner": True}
if sys.version_info >= (3, 12): # pragma: no cover
kwargs = kwargs | {"filter": "tar"}
tf.extract(member, destination, **kwargs)
files = [m.name for m in members]
else:
raise RuntimeError(
Expand Down
Loading