refactor: reuse the shared helpers left copied

Copies of helpers the first pass created, replaced by the helper:
- source_yaml_file for our YAML sources (generate_db read them in the
  locale's encoding, a syntax error named no file);
- data_dir_registry_at in registry_bundles, platform_registry_at (new,
  beside load_platform_registry) in the manifest;
- DATA_DIRS_FILE for the registry path five modules spelled;
- load_optional_database, sha1_at, VERSIONS_FILE, installer_module;
- DerivedView where a cache was keyed by id() of a dict;
- count_text and series where a plural or a list was written by hand.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:31:29 +01:00
1 parent 32a4ca1fa1
commit 036a6ebf29
35 files changed
+141 -170

No files matched your search

+4 -5
View File
@@ -14,6 +14,7 @@ from pathlib import Path
from xml.sax.saxutils import escape
from model.registry import load_platform_registry
from model.sources import source_yaml_file
from core.paths import REPO_ROOT
from core.text import count_text
from model import siteinputs
@@ -453,13 +454,11 @@ def emulator_names() -> dict[str, str]:
@cache
def _emulator_names_in(emulators_dir: str) -> dict[str, str]:
import yaml
names: dict[str, str] = {}
for _, emulator in CHAIN_EXAMPLES:
with open(Path(emulators_dir) / f"{emulator}.yml", encoding="utf-8") as handle:
label = str(yaml.safe_load(handle).get("emulator", emulator))
names[emulator] = re.sub(r"\s*\(.*\)$", "", label)
profile = source_yaml_file(Path(emulators_dir) / f"{emulator}.yml") or {}
label = str(profile.get("emulator", emulator))
names[emulator] = re.sub(r"\s*\(.*\)$", "", label)
return names
+3 -5
View File
@@ -9,6 +9,7 @@ from dataclasses import dataclass
from core.hashing import declared_hash_lists
from core.text import series
from model.database import sha1_at
from model.platforms import native_layer
from model.profiles import is_emulator
from resolve.cores import resolve_platform_cores
@@ -104,11 +105,8 @@ def _copy_cell(path: str, algos: list[str], db: dict | None) -> str:
"""The file a path holds, with its hashes in the algorithms declared."""
if not path:
return "-"
record: dict = next(
(rec | {"sha1": sha1} for sha1, rec in (db or {}).get("files", {}).items()
if rec.get("path") == path),
{},
)
sha1 = sha1_at(db or {}, path)
record: dict = (db or {})["files"][sha1] | {"sha1": sha1} if sha1 else {}
hashes = {algo: [str(record[algo]).lower()] for algo in algos if record.get(algo)}
shown = f"[{code_span(path)}]({fetch_url(path)})"
return f"{shown}<br>{_hash_cell(hashes)}" if hashes else shown
+2 -2
View File
@@ -26,7 +26,7 @@ from model.guides import PACKAGE_COMMAND, install_command
from model.largefiles import LARGE_FILES_CACHE, load_registered_paths
from model.platforms import load_platform_config
from model.profiles import load_emulator_profiles, unique_emulator_profiles
from model.registry import list_registered_platforms, load_platform_registry
from model.registry import VERSIONS_FILE, list_registered_platforms, load_platform_registry
from model.systems import system_index
from packs.coverage import verify_platform
from resolve.cores import resolve_platform_cores
@@ -144,7 +144,7 @@ def _coverage_inputs(db_path: Path, platforms_dir: str, emulators_dir: str) -> s
for path in sorted(p for p in root.resolve().rglob(pattern) if p.is_file()):
add_file(path)
for path in (REPO_ROOT / ".gitignore", REPO_ROOT / "_mame_clones.json",
REPO_ROOT / "data" / ".versions.json"):
REPO_ROOT / VERSIONS_FILE):
add_file(path)
digest.update(b"offline\0" + (b"1" if os.environ.get("RETROBIOS_OFFLINE") else b"0") + b"\n")
large = Path(LARGE_FILES_CACHE).resolve()