refactor: read an entry's target as a function

The emulator card read entry_target from the consumers object, which the tests stand in for with a namespace. It is a module function now, and the pairing test resolves an archive member through it as the site does.
This commit is contained in:
Abdessamad Derraz committed 2026-11-05 20:33:37 +01:00
1 parent add6619730
commit 213b20e2c8
3 files changed
+23 -21

No files matched your search

+15 -15
View File
@@ -546,20 +546,6 @@ class FileConsumers:
if member is not entry
}
@staticmethod
def entry_target(entry: dict, files: list[dict]) -> tuple[dict, str]:
"""The entry a profile entry resolves through, and its destination.
A ROM read inside an archive is the archive: FBNeo opens sm1.sm1 in
neogeo.zip, and resolved by its crc32 it credited a loose copy FBNeo
never opens, while no neogeo.zip card named FBNeo. The archive
members the profile reads decide between same-named copies, as in
the emulator pack and verify.
"""
if entry.get("archive"):
return archive_entry(entry["archive"], files), ""
return with_archive_members(entry, files), entry.get("path") or ""
def add_emulators(self, profiles: dict[str, dict]) -> None:
"""Each file a profile entry resolves to, a directory's members included.
@@ -588,13 +574,27 @@ class FileConsumers:
for dest, sha1 in members.items()
]
else:
found = [self.sha1_of(*self.entry_target(entry, files), owner=name)]
found = [self.sha1_of(*entry_target(entry, files), owner=name)]
for sha1 in found:
if sha1:
self.emulators.setdefault(sha1, set()).add(name)
self.emulator_entries.setdefault(sha1, {}).setdefault(name, index)
def entry_target(entry: dict, files: list[dict]) -> tuple[dict, str]:
"""The entry a profile entry resolves through, and its destination.
A ROM read inside an archive is the archive: FBNeo opens sm1.sm1 in
neogeo.zip, and resolved by its crc32 it credited a loose copy FBNeo
never opens, while no neogeo.zip card named FBNeo. The archive
members the profile reads decide between same-named copies, as in
the emulator pack and verify.
"""
if entry.get("archive"):
return archive_entry(entry["archive"], files), ""
return with_archive_members(entry, files), entry.get("path") or ""
def entry_source(f: dict, index: dict) -> str | None:
"""Where the collection holds a profile entry, or None.
+2 -2
View File
@@ -63,7 +63,7 @@ from common import (
)
from artifacts import ArtifactLockBusy, artifact_lock
from artifacts import json_text as _json_text
from cross_reference import FileConsumers, held_copy
from cross_reference import FileConsumers, entry_target, held_copy
from nativemode import check_label, digest_algorithm, reads_file_contents
@@ -8220,7 +8220,7 @@ def _render_emulator_file(
details.extend(_directory_copies(f, consumers))
if consumers:
sha1 = consumers.sha1_of(
*consumers.entry_target(f, profile.get("files") or []), owner=owner)
*entry_target(f, profile.get("files") or []), owner=owner)
held = consumers.path_of(sha1) if sha1 and in_repo else ""
parts = held.split("/")
if len(parts) >= 3 and parts[0] == "bios" and f.get("archive"):
+6 -4
View File
@@ -17,7 +17,7 @@ from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(REPO_ROOT / "scripts"))
from cross_reference import FileConsumers # noqa: E402
from cross_reference import FileConsumers, entry_target # noqa: E402
from generate_site import generate_system_page # noqa: E402
_TMP = tempfile.TemporaryDirectory()
@@ -246,7 +246,6 @@ class EveryReaderIsTheEmulatorPackFile(unittest.TestCase):
build_zip_contents_index, load_data_dir_registry,
load_emulator_profiles, resolve_local_file,
)
from validation import with_archive_members
db_path = REPO_ROOT / "database.json"
if not db_path.exists():
@@ -275,9 +274,12 @@ class EveryReaderIsTheEmulatorPackFile(unittest.TestCase):
if members:
from_trees |= {(sha1, name) for sha1 in members.values()}
continue
# A ROM read inside an archive is the archive, as the
# emulator pack resolves it (archive_entry).
target, dest = entry_target(entry, files)
path, status = resolve_local_file(
{**with_archive_members(entry, files), "source_profile": name},
db, zips, dest_hint=entry.get("path") or "",
{**target, "source_profile": name},
db, zips, dest_hint=dest,
data_dir_registry=registry,
)
if path and status not in ("not_found", "hash_mismatch"):