fix: read site manifests and archives from inputs

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 02:26:44 +01:00
1 parent 35b5458a2d
commit 137035d28b
7 files changed
+65 -17

No files matched your search

+1 -1
View File
@@ -626,7 +626,7 @@ def _write_navigation(run: _SiteRun, published_parts: dict[str, str]) -> None:
sys_id for cov in coverages.values() for sys_id in cov["config"].get("systems", {})
}
titles = {sys_id: system_name(sys_id) for sys_id in sorted(system_ids)}
sitestarlight.picker_data(REPO_ROOT / "install", public / "data" / "picker", titles)
sitestarlight.picker_data(siteinputs.manifests_dir(), public / "data" / "picker", titles)
total_pages = len(present)
print(f"\nGenerated {total_pages} pages in {run.args.docs_dir}/")
if stale:
+2 -1
View File
@@ -12,6 +12,7 @@ from collections.abc import Callable
from core.text import series
from core.hashing import parse_hash_list
from model import siteinputs
from model.collection import profiles_on_disk
from packs.crossref import FileConsumers
from romrecipes.romsets import dat_snapshots, usable_recipe
@@ -374,7 +375,7 @@ def _romset_line(f: dict) -> str:
when no recipe names the archive or the file is not on disk.
"""
recipes = romset_releases().get(str(f.get("name", "")))
path = REPO_ROOT / str(f.get("path", ""))
path = siteinputs.collection_path(str(f.get("path", "")))
if not recipes or not path.is_file():
return ""
try:
+6 -3
View File
@@ -12,7 +12,6 @@ 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
from sitegen import markup
@@ -529,9 +528,13 @@ def _mode_summary() -> str:
MINUI_EXAMPLES = (("Sony PlayStation", "PS"), ("Game Boy Advance", "GBA"), ("Sega Genesis", "MD"))
@cache
def minui_files() -> dict[str, list[str]]:
manifest = json.loads((REPO_ROOT / "install" / "minui.json").read_text(encoding="utf-8"))
return _minui_files_in(str(siteinputs.manifests_dir()))
@cache
def _minui_files_in(manifests_dir: str) -> dict[str, list[str]]:
manifest = json.loads((Path(manifests_dir) / "minui.json").read_text(encoding="utf-8"))
by_tag: dict[str, list[str]] = {}
for entry in manifest.get("files", []):
parts = str(entry.get("dest", "")).split("/")
+1 -2
View File
@@ -21,7 +21,6 @@ from model.registry import load_platform_registry
from resolve.nativemode import digest_algorithm
from installer_build.handhelds import GROUP_PAGE
from sitegen import handheld as sitehandheld, markup
from core.paths import REPO_ROOT
from core.sizes import size_text
from sitegen.guides import platform_args, terminal_tabs
from sitegen.home import next_block
@@ -299,7 +298,7 @@ def _computer_first(name: str, guide: Guide) -> bool:
def _ships_neogeo(name: str) -> bool:
"""Whether the setup's files hold `neogeo.zip`, the archive a reader most
often unzips by mistake: arcade BIOS sets are read zipped."""
manifest = REPO_ROOT / "install" / f"{name}.json"
manifest = siteinputs.manifests_dir() / f"{name}.json"
if not manifest.is_file():
return False
files = json.loads(manifest.read_text(encoding="utf-8")).get("files", [])
+13 -5
View File
@@ -8,6 +8,7 @@ import json
import re
import shlex
from collections import Counter
from pathlib import Path
from core.text import series
from model import siteinputs
@@ -20,7 +21,6 @@ from resolve.layout import runs_standalone, standalone_layout_path
from resolve.standalone import standalone_set
from resolve.validation import installed_everywhere, installed_with_emulator
from sitegen import markup
from core.paths import REPO_ROOT
from installer_build.module import installer_module
from sitegen.fields import search_excluded
from sitegen.guides import fence, platform_args, terminal_tabs
@@ -42,11 +42,15 @@ def _release_packs_in(platforms_dir: str) -> frozenset[str]:
return frozenset(list_release_pack_platforms(platforms_dir))
@functools.cache
def manifest_systems(platform: str) -> frozenset[str]:
"""The system ids a platform's install manifest records: --system
refuses any other."""
manifest = REPO_ROOT / "install" / f"{platform}.json"
return _manifest_systems_in(str(siteinputs.manifests_dir()), platform)
@functools.cache
def _manifest_systems_in(manifests_dir: str, platform: str) -> frozenset[str]:
manifest = Path(manifests_dir) / f"{platform}.json"
if not manifest.is_file():
return frozenset()
document = json.loads(manifest.read_text(encoding="utf-8"))
@@ -111,13 +115,17 @@ def install_commands(args: str = "", indent: str = "",
return lines
@functools.cache
def _published_emulator_names() -> dict[str, dict[str, str]]:
"""Per published manifest, every name `--emulator` accepts there and the
profile it stands for, as `install.py --list-emulators` prints them."""
return _published_emulator_names_in(str(siteinputs.manifests_dir()))
@functools.cache
def _published_emulator_names_in(manifests_dir: str) -> dict[str, dict[str, str]]:
installer = installer_module()
names: dict[str, dict[str, str]] = {}
for path in sorted((REPO_ROOT / "install").glob("*.json")):
for path in sorted(Path(manifests_dir).glob("*.json")):
manifest = json.loads(path.read_text(encoding="utf-8"))
names[path.stem] = installer.emulator_names(
manifest, manifest.get("files") or [], manifest.get("omitted_files") or [])
+5 -4
View File
@@ -113,11 +113,11 @@ def generate_files_page() -> str:
])
def data_directory_members(install_dir: Path = REPO_ROOT / "install") -> dict[str, dict[str, dict]]:
def data_directory_members(install_dir: Path | None = None) -> dict[str, dict[str, dict]]:
"""Each data directory's files with their sha1 and size, as the install
manifests record them for the installer to check."""
members: dict[str, dict[str, dict]] = {}
for path in sorted(install_dir.glob("*.json")):
for path in sorted((install_dir or siteinputs.manifests_dir()).glob("*.json")):
manifest = json.loads(path.read_text(encoding="utf-8"))
for tree in manifest.get("data_directories") or []:
members.setdefault(str(tree.get("ref", "")), {}).update(tree.get("files") or {})
@@ -318,7 +318,7 @@ def retired_records(retired: dict[str, dict], files: dict, locations: list[dict]
def _archive_member_records(entry: dict, sha1: str, url: str,
root: Path = REPO_ROOT) -> list[dict]:
root: Path | None = None) -> list[dict]:
"""The CRC32 of each member of a collection archive, read from its
central directory.
@@ -326,7 +326,8 @@ def _archive_member_records(entry: dict, sha1: str, url: str,
in a500.zip, 8484f426) found nothing: 26,014 of 33,403 members were in
no record. The record leads to the archive's card and names it.
"""
path = root / str(entry.get("path", ""))
rel = str(entry.get("path", ""))
path = root / rel if root is not None else siteinputs.collection_path(rel)
if not is_archive_path(path.name) or not path.is_file():
return []
try:
+37 -1
View File
@@ -87,6 +87,41 @@ class TheGivenDatabase(_Inputs):
other = {"name": "board.zip", "contents": [{"crc32": "deadbeef"}]}
self.assertEqual(render._entry_archives(other, files, {"board.zip": [SHA1]}), set())
def test_archive_members_are_read_from_the_given_collection(self) -> None:
import zipfile
from unittest import mock
from sitegen import cards, lookup
archive = self.db.parent / "bios" / "X" / "set.zip"
archive.parent.mkdir(parents=True)
with zipfile.ZipFile(archive, "w") as zf:
zf.writestr("a.rom", b"given")
crc = f"{zipfile.ZipFile(archive).getinfo('a.rom').CRC:08x}"
entry = {"name": "set.zip", "path": "bios/X/set.zip"}
self.use(db=self.db)
records = lookup._archive_member_records(entry, SHA1, "/x/")
self.assertEqual([r["name"] for r in records], ["a.rom"])
recipes: dict[str, list] = {"set.zip": [((("a.rom", crc),), "mame", [])]}
with mock.patch.object(cards, "romset_releases", return_value=recipes):
self.assertNotEqual(cards._romset_line(entry), "")
def test_the_manifest_readers_follow_the_given_manifests(self) -> None:
manifests = self.db.parent / "install"
manifests.mkdir()
(manifests / "fixture.json").write_text(json.dumps({
"files": [{"dest": "Bios/PS/neogeo.zip", "systems": ["fixture-system"]}],
"data_directories": [{"ref": "tree", "files": {"a": {"sha1": SHA1}}}],
}))
(manifests / "minui.json").write_text(json.dumps({"files": [{"dest": "Bios/PS/a.bin"}]}))
self.use(db=self.db)
from sitegen import lookup
self.assertEqual(install.manifest_systems("fixture"), frozenset({"fixture-system"}))
self.assertTrue(guidepage._ships_neogeo("fixture"))
self.assertEqual(diagrams.minui_files(), {"PS": ["a.bin"]})
self.assertEqual(lookup.data_directory_members(), {"tree": {"a": {"sha1": SHA1}}})
class TheGivenProfilesAndPlatforms(_Inputs):
def setUp(self) -> None:
@@ -191,7 +226,8 @@ class NoPageModuleReadsTheRepositoryInputs(unittest.TestCase):
def test_no_page_module_reads_the_repository_manifests(self) -> None:
modules = [SCRIPTS / "sitegen" / f"{name}.py"
for name in ("render", "platformfiles", "whichpack", "structured")]
for name in ("render", "platformfiles", "whichpack", "structured", "install",
"lookup", "build", "guidepage", "diagrams")]
found = [
f"{module.name}:{node.lineno}"
for module in modules