diff --git a/CHANGELOG.md b/CHANGELOG.md index f7294d0..2687069 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -40,7 +43,7 @@ boolean options, all defaulting to `True`: - The JSON output file is no longer generated by default. - The `--output ` option have been renamed to `--json-output ` - The `--json-output ` option must now be explicitly specified to enable JSON file generation. - + ### Fixed diff --git a/pyproject.toml b/pyproject.toml index c9c0c63..a5627b5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/src/spdx_diff/cli.py b/src/spdx_diff/cli.py index 83f1968..e930b80 100644 --- a/src/spdx_diff/cli.py +++ b/src/spdx_diff/cli.py @@ -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__ @@ -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: