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)