diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e6a3f3..77e438a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project will be documented in this file. ### Added + - Support zstd-compressed SPDX files. + ### Changed - Add custom `HelpFormatter` to render boolean flags in a compact `--[no-]flag` format instead of the default `--flag, --no-flag`. diff --git a/pyproject.toml b/pyproject.toml index 598df49..c9c0c63 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,10 @@ classifiers = [ "Topic :: Software Development :: Build Tools", ] +dependencies = [ + "backports.zstd; python_version < '3.14'" +] + [project.scripts] spdx-diff = "spdx_diff.cli:main" diff --git a/src/spdx_diff/cli.py b/src/spdx_diff/cli.py index 0505025..83f1968 100644 --- a/src/spdx_diff/cli.py +++ b/src/spdx_diff/cli.py @@ -16,6 +16,11 @@ from collections import defaultdict from typing import Any +if sys.version_info >= (3, 14): + from compression import zstd +else: + from backports import zstd + from . import __version__ _logger = logging.getLogger(__name__) @@ -53,9 +58,14 @@ def _parse(self, json_path: pathlib.Path) -> None: :param json_path: Path the JSON file. """ _logger.info("Opening SPDX file: %s", json_path) + try: - with json_path.open(encoding="utf-8") as f: - data = json.load(f) + if json_path.suffix == ".zst": + with zstd.open(json_path, "rt") as f: + data = json.load(f) + else: + with json_path.open(encoding="utf-8") as f: + data = json.load(f) except (OSError, ValueError) as e: raise ValueError("Failed to read or parse %s", json_path) from e