From 291f58327616dba9b640eda5ec2ceacb99eae556 Mon Sep 17 00:00:00 2001 From: "John T. Wodder II" Date: Fri, 22 Sep 2023 14:17:16 -0400 Subject: [PATCH] Use tarfile `filter` in Python 3.12+ Closes #48. --- CHANGELOG.md | 1 + test/test_end2end.py | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ed09cc..906960c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ v2.3.0 (in development) - Raise a `ConfigError` if the selected `tool.versioningit.format` field is not a string - Update tests for pydantic 2.0 +- Update tests for Python 3.12 v2.2.0 (2023-02-11) ------------------- diff --git a/test/test_end2end.py b/test/test_end2end.py index 9cd76c2..86412ed 100644 --- a/test/test_end2end.py +++ b/test/test_end2end.py @@ -277,9 +277,16 @@ def test_build_from_sdist(tmp_path: Path) -> None: # This test is used to check that building from an sdist succeeds even when # a VCS is not installed, though it passes when one is installed as well. srcdir = tmp_path / "src" - shutil.unpack_archive( - str(DATA_DIR / "mypackage-0.1.0.post4+g56ed573.tar.gz"), str(srcdir) - ) + if sys.version_info >= (3, 12): + shutil.unpack_archive( + str(DATA_DIR / "mypackage-0.1.0.post4+g56ed573.tar.gz"), + str(srcdir), + filter="data", + ) + else: + shutil.unpack_archive( + str(DATA_DIR / "mypackage-0.1.0.post4+g56ed573.tar.gz"), str(srcdir) + ) (srcsubdir,) = srcdir.iterdir() init_path = Path("src", "mypackage", "__init__.py") init_src = (srcsubdir / init_path).read_text() @@ -406,7 +413,10 @@ def get_repo_status(repodir: Path) -> str: def unpack_sdist(dist_dir: Path, tmp_path: Path) -> Path: (sdist,) = dist_dir.glob("*.tar.gz") - shutil.unpack_archive(str(sdist), str(tmp_path / "sdist")) + if sys.version_info >= (3, 12): + shutil.unpack_archive(str(sdist), str(tmp_path / "sdist"), filter="data") + else: + shutil.unpack_archive(str(sdist), str(tmp_path / "sdist")) (sdist_src,) = (tmp_path / "sdist").iterdir() return sdist_src