From ee1947def8b306989c892b4d0c01001f20a86a3b Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Wed, 27 Nov 2024 09:13:08 +0100 Subject: [PATCH 1/3] Catch tar deprecation warning in extract_archive() --- audeer/core/io.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index f1f03b2..6f5fb7d 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -8,6 +8,7 @@ import tarfile import typing import urllib.request +import warnings import zipfile from audeer.core.path import path as safe_path @@ -369,7 +370,12 @@ def extract_archive( desc=desc, disable=disable, ): - tf.extract(member, destination, numeric_owner=True) + # In Python 3.12 the `filter` argument was introduced. + # In a later version we should use `filter="tar"`, + # until then we catch the deprecation warning + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + tf.extract(member, destination, numeric_owner=True) files = [m.name for m in members] else: raise RuntimeError( From a91c5ea87d3ffdfa0240afc6e752cd721cb25157 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Wed, 27 Nov 2024 09:20:28 +0100 Subject: [PATCH 2/3] Set filter argument instead --- audeer/core/io.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index 6f5fb7d..635442c 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -5,10 +5,10 @@ import itertools import os import shutil +import sys import tarfile import typing import urllib.request -import warnings import zipfile from audeer.core.path import path as safe_path @@ -370,11 +370,16 @@ def extract_archive( desc=desc, disable=disable, ): - # In Python 3.12 the `filter` argument was introduced. - # In a later version we should use `filter="tar"`, - # until then we catch the deprecation warning - with warnings.catch_warnings(): - warnings.simplefilter("ignore") + # In Python 3.12 the `filter` argument was introduced, + # 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 + if sys.version_info >= (3, 12): + tf.extract( + member, destination, numeric_owner=True, filter="tar" + ) + else: tf.extract(member, destination, numeric_owner=True) files = [m.name for m in members] else: From 937013ac2c9a517af2e93221bdffebf44972a476 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Wed, 27 Nov 2024 09:26:13 +0100 Subject: [PATCH 3/3] Try to fix coverage --- audeer/core/io.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/audeer/core/io.py b/audeer/core/io.py index 635442c..564a7bd 100644 --- a/audeer/core/io.py +++ b/audeer/core/io.py @@ -375,12 +375,10 @@ def extract_archive( # see # https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter # noqa: E501 - if sys.version_info >= (3, 12): - tf.extract( - member, destination, numeric_owner=True, filter="tar" - ) - else: - tf.extract(member, destination, numeric_owner=True) + 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(