Skip to content

Commit 442eecb

Browse files
committed
Skip pyzstd with Python 3.14+
3.14 has builtin zstd support, so use the builtin one there.
1 parent cca2a11 commit 442eecb

File tree

5 files changed

+53
-38
lines changed

5 files changed

+53
-38
lines changed

msys2_devtools/db.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,6 @@
11
import io
22

3-
from pyzstd import ZstdFile, ZstdError
4-
import tarfile
5-
6-
7-
class ExtTarFile(tarfile.TarFile):
8-
"""Extends TarFile to support zstandard"""
9-
10-
@classmethod
11-
def zstdopen(cls, name, mode="r", fileobj=None, **kwargs): # type: ignore
12-
"""Open zstd compressed tar archive"""
13-
14-
if mode not in ("r", "w", "x", "a"):
15-
raise ValueError("mode must be 'r', 'w' or 'x' or 'a'")
16-
17-
zstfileobj = None
18-
try:
19-
zstfileobj = ZstdFile(fileobj or name, mode)
20-
if "r" in mode:
21-
zstfileobj.peek(1) # raises ZstdError if not a zstd file
22-
except (ZstdError, EOFError) as e:
23-
if zstfileobj is not None:
24-
zstfileobj.close()
25-
raise tarfile.ReadError("not a zstd file") from e
26-
27-
try:
28-
t = cls.taropen(name, mode, zstfileobj, **kwargs)
29-
except Exception:
30-
zstfileobj.close()
31-
raise
32-
33-
t._extfileobj = False
34-
return t
35-
36-
OPEN_METH = {"zstd": "zstdopen", **tarfile.TarFile.OPEN_METH}
3+
from .exttarfile import ExtTarFile
374

385

396
def parse_desc(t: str) -> dict[str, list[str]]:

msys2_devtools/exttarfile.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import tarfile
2+
3+
HAS_ZSTD = True
4+
try:
5+
from compression import zstd
6+
except ImportError:
7+
HAS_ZSTD = False
8+
9+
ExtTarFile: type[tarfile.TarFile]
10+
11+
if not HAS_ZSTD:
12+
from pyzstd import ZstdFile, ZstdError
13+
14+
class ZstTarFile(tarfile.TarFile):
15+
"""Extends TarFile to support zstandard"""
16+
17+
@classmethod
18+
def zstdopen(cls, name, mode="r", fileobj=None, **kwargs): # type: ignore
19+
"""Open zstd compressed tar archive"""
20+
21+
if mode not in ("r", "w", "x", "a"):
22+
raise ValueError("mode must be 'r', 'w' or 'x' or 'a'")
23+
24+
zstfileobj = None
25+
try:
26+
zstfileobj = ZstdFile(fileobj or name, mode)
27+
if "r" in mode:
28+
zstfileobj.peek(1) # raises ZstdError if not a zstd file
29+
except (ZstdError, EOFError) as e:
30+
if zstfileobj is not None:
31+
zstfileobj.close()
32+
raise tarfile.ReadError("not a zstd file") from e
33+
34+
try:
35+
t = cls.taropen(name, mode, zstfileobj, **kwargs)
36+
except Exception:
37+
zstfileobj.close()
38+
raise
39+
40+
t._extfileobj = False
41+
return t
42+
43+
OPEN_METH = {"zst": "zstdopen", **tarfile.TarFile.OPEN_METH}
44+
45+
ExtTarFile = ZstTarFile
46+
else:
47+
assert zstd
48+
ExtTarFile = tarfile.TarFile

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies = [
1010
"tabulate>=0.9.0,<0.10",
1111
"requests>=2.28.2,<3",
1212
"pydantic>=2.0,<3",
13-
"pyzstd>=0.18.0,<0.19",
13+
"pyzstd>=0.18.0,<0.19; python_version < '3.14'",
1414
]
1515

1616
[project.optional-dependencies]

tests/test_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_parse_desc():
3434

3535
def test_zstd():
3636
fileobj = io.BytesIO()
37-
with ExtTarFile.open(fileobj=fileobj, mode='w:zstd') as tar:
37+
with ExtTarFile.open(fileobj=fileobj, mode='w:zst') as tar:
3838
data = "Hello world!".encode('utf-8')
3939
info = tarfile.TarInfo("test.txt")
4040
info.size = len(data)

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)