From 73e101855c80a24fb85e31ba3a97b488ed72ab8e Mon Sep 17 00:00:00 2001 From: M Bussonnier Date: Wed, 8 Oct 2025 16:21:14 +0200 Subject: [PATCH] Use compression.zstd/backports.zstd instead of zstandard In particular zstandard does not ships with all the wheels of backports.zstd, and remove one dependency on 3.14+. Drawback might be some platforms may not package backports.zstd yet Closes #2077 --- pyproject.toml | 2 +- src/hatch/python/resolve.py | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fdee18f6e..63c8dfaf0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ dependencies = [ "userpath~=1.7", "uv>=0.5.23", "virtualenv>=20.26.6", - "zstandard<1", + "backports.zstd; python_version<'3.14'", ] dynamic = ["version"] diff --git a/src/hatch/python/resolve.py b/src/hatch/python/resolve.py index cf17a29b7..672e40e16 100644 --- a/src/hatch/python/resolve.py +++ b/src/hatch/python/resolve.py @@ -79,15 +79,16 @@ def unpack(self, archive: Path, directory: Path) -> None: elif self.source.endswith((".tar.zst", ".tar.zstd")): import tarfile - import zstandard - - with open(archive, "rb") as ifh: - dctx = zstandard.ZstdDecompressor() - with dctx.stream_reader(ifh) as reader, tarfile.open(mode="r|", fileobj=reader) as tf: - if sys.version_info[:2] >= (3, 12): - tf.extractall(directory, filter="data") - else: - tf.extractall(directory) # noqa: S202 + if sys.version_info < (3, 14): + from backports import zstd + else: + from compression import zstd + + with zstd.open(archive) as reader, tarfile.open(mode="r|", fileobj=reader) as tf: + if sys.version_info[:2] >= (3, 12): + tf.extractall(directory, filter="data") + else: + tf.extractall(directory) # noqa: S202 else: message = f"Unknown archive type: {archive}" raise ValueError(message)