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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
14 changes: 12 additions & 2 deletions src/spdx_diff/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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

Expand Down
Loading