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

+6 -6
View File
@@ -30,7 +30,7 @@ from profiling.citations import collect_citations
from profiling.repos import select_views
from model.sourceref import ref_role, split_source_ref
from model.profiles import ProfileSelectionError, load_emulator_profiles, resolve_profile_name
from model.safeparse import yaml_load
from model.sources import source_yaml_file
# Ways a program asks for somewhere to read from.
SIGNALS = (
@@ -58,8 +58,7 @@ def audit(
name: str, emulators_dir: str, cache_dir: str, offline: bool
) -> list[tuple[str, str]] | None:
"""Signals found in the sources a fileless profile cites."""
with open(os.path.join(emulators_dir, f"{name}.yml"), encoding="utf-8") as handle:
document = yaml_load(handle) or {}
document = source_yaml_file(os.path.join(emulators_dir, f"{name}.yml")) or {}
if document.get("files"):
return None
if document.get("type") == "alias":
@@ -136,9 +135,10 @@ def main() -> None:
known = sorted(path.stem for path in Path(args.emulators_dir).glob("*.yml"))
names = []
for name in known:
with open(Path(args.emulators_dir) / f"{name}.yml", encoding="utf-8") as handle:
if not _settled_before_reading(yaml_load(handle) or {}):
names.append(name)
if not _settled_before_reading(
source_yaml_file(Path(args.emulators_dir) / f"{name}.yml") or {}
):
names.append(name)
flagged = unreachable = 0
for name in names: