Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ All notable changes to this project will be documented in this file.

### Changed

- zstandard fallback import added for python <3.14
- Zstd libraries are optional dependencies

### Fixed

### Removed
Expand Down Expand Up @@ -40,7 +43,7 @@ boolean options, all defaulting to `True`:
- The JSON output file is no longer generated by default.
- The `--output <PATH>` option have been renamed to `--json-output <PATH>`
- The `--json-output <PATH>` option must now be explicitly specified to enable JSON file generation.


### Fixed

Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ classifiers = [
"Topic :: Software Development :: Build Tools",
]

dependencies = [
"backports.zstd; python_version < '3.14'"
[project.optional-dependencies]
zstd = [
"backports.zstd;python_version<'3.14'",
]
zstandard = [
"zstandard;python_version<'3.14'",
]

[project.scripts]
Expand Down
17 changes: 14 additions & 3 deletions src/spdx_diff/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
from typing import Any

if sys.version_info >= (3, 14):
from compression import zstd
from compression.zstd import open as open_zstd
else:
from backports import zstd
try:
from backports.zstd import open as open_zstd # type: ignore[import-not-found]
except ImportError:
try:
from zstandard import open as open_zstd # type: ignore[import-not-found]
except ImportError:
open_zstd = None

from . import __version__

Expand Down Expand Up @@ -61,7 +67,12 @@ def _parse(self, json_path: pathlib.Path) -> None:

try:
if json_path.suffix == ".zst":
with zstd.open(json_path, "rt") as f:
if open_zstd is None:
raise RuntimeError(
"Zstd support is not available."
"Please install the 'zstandard' package."
)
with open_zstd(json_path, "rb") as f:
data = json.load(f)
else:
with json_path.open(encoding="utf-8") as f:
Expand Down