Coverage for src/backoffice/utils.py: 0%
28 statements
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-12 10:26 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2025-11-12 10:26 +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 as cached_download
16from backoffice.utils_pure import (
17 get_all_tool_report_paths as get_all_tool_report_paths,
18)
19from backoffice.utils_pure import get_summary_file_path
21if TYPE_CHECKING:
22 from ruyaml import YAML
23else:
24 try:
25 from ruyaml import YAML
26 except ImportError:
27 from ruamel.yaml import YAML
29yaml = YAML(typ="safe")
32def get_rdf_content_from_url(url: str, sha256: str) -> dict[str, Any]:
33 local_path = cached_download(url, sha256)
34 return yaml.load(local_path)
37def get_summary(item_id: str, version: str) -> "InitialSummary | CompatibilitySummary":
38 """Retrieve the summary for a specific item and version."""
39 summary_path = get_summary_file_path(item_id, version)
40 if not summary_path.exists():
41 return InitialSummary(
42 rdf_content={},
43 rdf_yaml_sha256="",
44 status="untested",
45 )
47 with summary_path.open(encoding="utf-8") as f:
48 data = json.load(f)
50 try:
51 return CompatibilitySummary.model_validate(data)
52 except ValidationError:
53 return InitialSummary.model_validate(data)