refactor: split crossref into its three subjects

FileConsumers, held_copy and entry_target move to packs/consumers.py, the
data/ and bios/ ZIP index to packs/supplemental.py, the launcher-name report
to packs/crossreflaunchers.py and the set-aside labels with
profile_breakdown to packs/crossreftext.py. The site no longer imports the
gap engine to learn who reads a file.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 21:02:44 +01:00
1 parent cdbde88017
commit 3344cfd2fb
35 files changed
+806 -768

No files matched your search

+1
View File
@@ -36,6 +36,7 @@ COMMANDS = {
"cross_reference.py": (
"packs/crossref.py", "packs/crossrefscope.py", "packs/crossrefrun.py",
"packs/crossreflaunchers.py", "packs/crossreftext.py", "packs/crossrefreport.py",
"packs/supplemental.py",
),
"slots.py": ("packs/slots.py", "resolve/collisions.py", "packs/slotscan.py", "packs/slotreport.py"),
"validate_pr.py": (
+10 -10
View File
@@ -4489,7 +4489,7 @@ class ASameNamedMemberIsNotTheFile(unittest.TestCase):
while verify --emulator said missing."""
def test_a_declared_hash_decides_a_member_or_data_hit(self):
from scripts.packs import crossref
from scripts.packs import supplemental
tmp = Path(tempfile.mkdtemp())
self.addCleanup(lambda: __import__("shutil").rmtree(tmp, True))
@@ -4498,14 +4498,14 @@ class ASameNamedMemberIsNotTheFile(unittest.TestCase):
(tmp / "bios").mkdir()
with zipfile.ZipFile(tmp / "bios" / "extras.zip", "w") as zf:
zf.writestr("files/other.ttf", b"MEMBER FONT")
names = crossref.build_supplemental_index(str(tmp / "data"), str(tmp / "bios"))
names = supplemental.build_supplemental_index(str(tmp / "data"), str(tmp / "bios"))
for fname, data in (("font.ttf", b"DATA FONT"), ("other.ttf", b"MEMBER FONT")):
with self.subTest(name=fname):
held = {"name": fname, "sha1": hashlib.sha1(data).hexdigest()}
other = {"name": fname, "sha1": "0" * 40}
self.assertTrue(crossref._data_hit(fname, None, held, names))
self.assertFalse(crossref._data_hit(fname, None, other, names))
self.assertTrue(crossref._data_hit(fname, None, {"name": fname}, names))
self.assertTrue(supplemental.data_hit(fname, None, held, names))
self.assertFalse(supplemental.data_hit(fname, None, other, names))
self.assertTrue(supplemental.data_hit(fname, None, {"name": fname}, names))
class AnEmptyTargetIsNotEveryCore(unittest.TestCase):
@@ -5832,7 +5832,7 @@ class CollectionCardsCarryFullHashes(unittest.TestCase):
CRC32 or SHA256."""
def test_every_hash_in_full(self):
from scripts.packs.crossref import FileConsumers
from scripts.packs.consumers import FileConsumers
from scripts.sitegen.cards import system_file_card
entry = {"name": "DUKE.RTS", "path": "bios/x/DUKE.RTS", "size": 10,
@@ -5886,7 +5886,7 @@ class AVariantCardSaysWhatToSaveItAs(unittest.TestCase):
the storage name, and nothing said RetroBat looks for advision.zip."""
def test_the_name_to_save_it_under(self):
from scripts.packs.crossref import FileConsumers
from scripts.packs.consumers import FileConsumers
from scripts.sitegen.cards import system_file_card
entry = {"name": "advision.zip", "size": 10, "sha1": "a" * 40,
@@ -6168,15 +6168,15 @@ class AHashListIsReadOneWay(unittest.TestCase):
profile_sync looked the whole string up and called it missing."""
def test_every_reader_splits_the_list(self):
from scripts.packs.crossref import _declared_content
from scripts.packs.supplemental import declared_content
from scripts.core.hashing import parse_hash_list
from scripts.profiling.citations import entry_hashes
a, b = "a" * 64, "B" * 64
entry = {"name": "BS-X.bin", "sha256": f"{a}, {b}", "crc32": "0xDEADBEEF"}
self.assertEqual(parse_hash_list(entry["sha256"]), [a, b.lower()])
self.assertEqual(_declared_content(entry)["sha256"], {a, b.lower()})
self.assertEqual(_declared_content(entry)["crc32"], {"deadbeef"})
self.assertEqual(declared_content(entry)["sha256"], {a, b.lower()})
self.assertEqual(declared_content(entry)["crc32"], {"deadbeef"})
self.assertEqual(set(entry_hashes(entry)), {a, b.lower(), "deadbeef"})
+2 -2
View File
@@ -304,7 +304,7 @@ class AMemberNameIsNotALooseFile(unittest.TestCase):
no archive member names, shipped nothing."""
def test_verify_reads_undeclared_files_as_the_builder_does(self):
from packs import crossref
from packs import supplemental
emulator_profiles_cache.clear()
root = Path(tempfile.mkdtemp())
@@ -324,7 +324,7 @@ class AMemberNameIsNotALooseFile(unittest.TestCase):
db = {"files": {}, "indexes": {"by_md5": {}, "by_name": {}, "by_crc32": {},
"by_path_suffix": {}}}
config = load_platform_config("fakeplat", str(root / "platforms"))
with mock.patch.object(crossref, "build_supplemental_index",
with mock.patch.object(supplemental, "build_supplemental_index",
lambda *a, **k: {"315-6146.bin"}):
result = verify_platform(config, db, str(root / "emulators"))
self.assertEqual(
+2 -1
View File
@@ -16,7 +16,8 @@ import tempfile
import unittest
from pathlib import Path
from packs.crossref import build_supplemental_index, cross_reference, entry_source
from packs.crossref import cross_reference, entry_source
from packs.supplemental import build_supplemental_index
from packs.crossreftext import print_report
REPO_ROOT = Path(__file__).resolve().parent.parent
+1 -1
View File
@@ -15,7 +15,7 @@ import tempfile
import unittest
from pathlib import Path
from packs.crossref import FileConsumers, entry_target
from packs.consumers import FileConsumers, entry_target
from sitegen.systempages import generate_system_page
REPO_ROOT = Path(__file__).resolve().parent.parent
+1 -1
View File
@@ -34,7 +34,7 @@ from model.platforms import load_platform_config
from packs.crossreflaunchers import LAUNCHER_READS_KEY, LAUNCHER_UNPROVEN_KEY
from packs.crossreftext import print_launcher_reads
from packs.strictgate import platform_strict_failure
from packs.crossref import launcher_file_names, launcher_reads_not_held
from packs.crossreflaunchers import launcher_file_names, launcher_reads_not_held
ROOT = Path(__file__).resolve().parent.parent
+3 -3
View File
@@ -17,7 +17,7 @@ import tempfile
import unittest
from pathlib import Path
from packs import crossref
from packs.consumers import FileConsumers
from packs import slots
from core.ziptools import build_zip_contents_index
from model.database import load_database
@@ -37,7 +37,7 @@ class ReadersNameTheOwner(unittest.TestCase):
cls.sha1_by_path = {r["path"]: s for s, r in cls.db["files"].items()}
def test_the_site_credits_the_copy_the_pack_ships(self):
consumers = crossref.FileConsumers(
consumers = FileConsumers(
self.db, build_zip_contents_index(self.db)
)
consumers.add_emulators(self.profiles)
@@ -97,7 +97,7 @@ class EachForkReadsItsOwnCopy(unittest.TestCase):
self._tree.cleanup()
def test_the_site_credits_each_owner_with_its_copy(self):
consumers = crossref.FileConsumers(self.db, data_dir_registry={})
consumers = FileConsumers(self.db, data_dir_registry={})
consumers.add_emulators({
owner: {"type": "standalone", "files": [{"name": self.NAME}]}
for owner in self.sha1_of
+1 -1
View File
@@ -76,7 +76,7 @@ class AHeldEntrySaysWhere(unittest.TestCase):
import zipfile
from sitegen import emulatorcards
from packs.crossref import FileConsumers, held_copy
from packs.consumers import FileConsumers, held_copy
with tempfile.TemporaryDirectory() as tmp:
data, bios = Path(tmp) / "data", Path(tmp) / "bios"
+5 -5
View File
@@ -688,7 +688,7 @@ class AHashFindsEveryPageThatNamesIt(unittest.TestCase):
from sitegen import lookup
from model.platforms import load_platform_config
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
from core.ziptools import build_zip_contents_index
root = Path(__file__).resolve().parents[1]
@@ -921,7 +921,7 @@ class AFileHasAnAddressByContent(unittest.TestCase):
/ "site.ts").read_text()
self.assertIn("api/v1/lookup/", script)
self.assertIn("params.has('sha1')", script)
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
card = "\n".join(cards.system_file_card(
{"name": "x.rom", "sha1": "ab" * 20, "size": 1}, FileConsumers({"files": {}}),
@@ -937,7 +937,7 @@ class ACardNamesThePacksThatInstallIt(unittest.TestCase):
def test_a_manifest_destination_reaches_the_card(self):
import json as _json
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
from sitegen.cards import _installed_places
with tempfile.TemporaryDirectory() as tmp:
@@ -1196,7 +1196,7 @@ class TheOneLinerIsWhereUsersLand(unittest.TestCase):
def test_platform_and_system_pages(self):
from sitegen import platformpage
from sitegen import systempages
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
cov = {"platform": "Batocera", "mode": "md5", "present": 0, "total": 0,
"verified": 0, "missing": 0, "details": [], "config": {"systems": {}}}
@@ -1281,7 +1281,7 @@ class EveryPageLinksItsOwnData(unittest.TestCase):
from sitegen import dataexports
from sitegen import platformpage
from sitegen import systempages
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
cov = {"platform": "Batocera", "mode": "md5", "present": 0, "total": 0,
"verified": 0, "missing": 0, "details": [], "config": {"systems": {}}}
+6 -6
View File
@@ -184,7 +184,7 @@ class FileCardsLinkTheReadingEntry(unittest.TestCase):
"""The platform links landed on their section, the emulator links on
the top of a page of a hundred entries."""
from sitegen import cards
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
consumers = FileConsumers({"files": {}})
files = [{"name": "scph1001.bin"}, {"name": "scph5501.bin"},
@@ -213,7 +213,7 @@ class DirectoryMembersNameTheirEmulator(unittest.TestCase):
from core.ziptools import build_zip_contents_index
from model.database import load_database
from model.profiles import load_emulator_profiles
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
cls.db = load_database(str(REPO_ROOT / "database.json"))
if cls.SHA1 not in cls.db.get("files", {}):
@@ -410,7 +410,7 @@ class TheSearchLandsOnTheCard(unittest.TestCase):
def test_a_system_card_is_a_heading_with_its_anchor(self):
from sitegen import cards
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
entry = {"name": "a.bin", "sha1": "a" * 40, "md5": "b" * 32, "size": 3}
lines = cards.system_file_card(entry, FileConsumers({"files": {}}))
@@ -426,7 +426,7 @@ class TheSearchSkipsLinkLists(unittest.TestCase):
def test_a_system_card_keeps_its_name_and_skips_its_body(self):
from sitegen import cards
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
consumers = FileConsumers({"files": {}})
sha1 = "a" * 40
@@ -447,7 +447,7 @@ class TheSearchSkipsLinkLists(unittest.TestCase):
def test_a_game_data_card_skips_its_name_too(self):
from sitegen import cards
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
entry = {"name": "0.ogg", "sha1": "a" * 40, "size": 3}
lines = cards.system_file_card(
@@ -520,7 +520,7 @@ class AMemberIsReadInItsArchive(unittest.TestCase):
from sitegen import emulatorcards
from resolve.archives import archive_entry
from resolve.localfile import resolve_local_file
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
db = json.loads((REPO_ROOT / "database.json").read_text(encoding="utf-8"))
profile = yaml.safe_load((REPO_ROOT / "emulators" / "fbneo.yml").read_text(encoding="utf-8"))
+1 -1
View File
@@ -159,7 +159,7 @@ class AnIdNamesOneCardPerPage(unittest.TestCase):
the same id, and the deployed site refused 20 pages."""
def test_the_second_card_has_no_id(self):
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
# Sega keeps small consoles on its page: Nintendo and Sony give every
# console a page of its own (CONSOLE_PAGES).
+2 -2
View File
@@ -53,7 +53,7 @@ from sitegen import systempages
from sitegen import systemsindex
from sitegen import render as siterender
from model import systemnames
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
from sitegen import ogcards
from sitegen.diagrams import wrap
from core.anchors import toc_slug
@@ -1279,7 +1279,7 @@ class EachFileDownloadsFromItsCard(unittest.TestCase):
fourth of a card's facts."""
def test_the_card_title_holds_the_download(self) -> None:
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
f = _naomi_file("apple2-asoft-auto.rom", "3", "bios/Apple/Apple II/apple2-asoft-auto.rom")
title = next(line for line in sitegen_cards.system_file_card(f, FileConsumers({"files": {}}))
+1 -1
View File
@@ -21,7 +21,7 @@ from sitegen import systempages
from sitegen import starlight as sitestarlight
from sitegen import render as siterender
from sitegen import markup
from packs.crossref import FileConsumers
from packs.consumers import FileConsumers
def _file(name: str, index: int, console: str, maker: str = "Maker") -> dict:
+2 -2
View File
@@ -341,7 +341,7 @@ class TheGapHeadingAddsUp(unittest.TestCase):
16 entries were set aside without a word."""
def test_every_entry_is_counted_once(self):
from packs import crossref
from packs import crossref, crossreftext
files = [
{"name": "kick.rom", "required": True},
@@ -358,7 +358,7 @@ class TheGapHeadingAddsUp(unittest.TestCase):
all_declared={"kick.rom": [(None, "kick.rom")]})
data = report["emu"]
self.assertEqual(
crossref.profile_breakdown(data),
crossreftext.profile_breakdown(data),
"1 declared by platforms, 3 undeclared, 1 unsourceable, "
"2 set aside (1 other versions of a slot, 1 outside the pack)",
)
+2 -2
View File
@@ -17,7 +17,7 @@ import zipfile
from pathlib import Path
from core.ziptools import build_zip_contents_index, zip_members
from packs.crossref import _zip_members
from packs.supplemental import archive_members
from packs.integrity import _same_content
from sitegen.cards import _release_name
from sitegen.lookup import _archive_member_records
@@ -55,7 +55,7 @@ class VariantArchives(unittest.TestCase):
zip_members(garbage)
def test_the_gap_report_lists_the_members_of_a_copy(self):
found = dict(_zip_members(self.root / "bios"))
found = dict(archive_members(self.root / "bios"))
self.assertEqual(found[str(self.variant)], ["a.rom", "only.rom"])
def test_a_copy_answers_only_for_what_no_primary_holds(self):