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

+11 -9
View File
@@ -16,6 +16,7 @@ except ImportError:
yaml = None
from core.hashing import compute_hashes, parse_hash_list, stream_hashes
from core.memo import DerivedView
from model.nodedup import in_nodedup_dir
from model.platforms import load_platform_config
from model.profiles import load_emulator_profiles
@@ -846,19 +847,20 @@ def placement(
return Placement(tuple(sorted(homes)))
_HELD_DIRECTORIES: dict[int, frozenset[str]] = {}
def _directories_of(files: dict) -> frozenset[str]:
return frozenset(
path.rsplit("/", 1)[0] + "/"
for record in files.values()
if "/" in (path := record.get("path") or "") and "/.variants/" not in path
)
_held_view = DerivedView(_directories_of)
def _held_directories(db: dict | None) -> frozenset[str]:
"""Every directory a file of the database sits in, .variants/ aside."""
key = id(db)
if key not in _HELD_DIRECTORIES:
_HELD_DIRECTORIES[key] = frozenset(
path.rsplit("/", 1)[0] + "/"
for record in (db or {}).get("files", {}).values()
if "/" in (path := record.get("path") or "") and "/.variants/" not in path
)
return _HELD_DIRECTORIES[key]
return _held_view((db or {}).get("files", {}))
def _directory_tail(db: dict | None, directory: str) -> str: