Coverage for src/backoffice/utils.py: 0%
26 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-13 03:07 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-13 03:07 +0000
1"""utility functions"""
3import json
4from typing import TYPE_CHECKING, Any
6try:
7 from pydantic import ValidationError
8except ImportError as e:
9 raise ImportError(
10 "pydantic is required for backoffice.utils. "
11 "Please install `backoffice[dev]` or use backoffice.utils_plain."
12 ) from e
14from backoffice.compatibility import CompatibilitySummary, InitialSummary
15from backoffice.utils_pure import cached_download, get_summary_file_path
17if TYPE_CHECKING:
18 from ruyaml import YAML
19else:
20 try:
21 from ruyaml import YAML
22 except ImportError:
23 from ruamel.yaml import YAML
25yaml = YAML(typ="safe")
28def get_rdf_content_from_url(url: str, sha256: str) -> dict[str, Any]:
29 local_path = cached_download(url, sha256)
30 return yaml.load(local_path)
33def get_summary(item_id: str, version: str) -> "InitialSummary | CompatibilitySummary":
34 """Retrieve the summary for a specific item and version."""
35 summary_path = get_summary_file_path(item_id, version)
36 if not summary_path.exists():
37 return InitialSummary(
38 rdf_content={},
39 rdf_yaml_sha256="",
40 status="untested",
41 )
43 with summary_path.open(encoding="utf-8") as f:
44 data = json.load(f)
46 try:
47 return CompatibilitySummary.model_validate(data)
48 except ValidationError:
49 return InitialSummary.model_validate(data)