fix: read site manifests and zips from the inputs

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent 8603885fda
commit 0d44254504
6 files changed
+64 -8

No files matched your search

+13
View File
@@ -19,6 +19,8 @@ class SiteInputs:
db: Path = REPO_ROOT / "database.json"
emulators: Path = REPO_ROOT / "emulators"
platforms: Path = REPO_ROOT / "platforms"
# The install manifests; None places them beside the database.
manifests: Path | None = None
_current = [SiteInputs()]
@@ -41,3 +43,14 @@ def bios_dir(db: dict) -> Path:
"""
named = Path(str(db.get("bios_dir") or "bios"))
return named if named.is_absolute() else current().db.parent / named
def collection_path(rel: str) -> Path:
"""A path database.json names, under the database's own folder."""
return current().db.parent / rel
def manifests_dir() -> Path:
"""The install manifests built from the collection the inputs name."""
inputs = current()
return inputs.manifests or inputs.db.parent / "install"
+2 -3
View File
@@ -15,7 +15,6 @@ from model.profiles import is_emulator, upstream_profile_index
from model.systemnames import system_name
from sitegen import entries as siteentries, markup
from sitegen.config import REPO_URL, date_line
from core.paths import REPO_ROOT
from core.sizes import size_text
from sitegen.fields import hash_spans, search_excluded
from sitegen.parts import (
@@ -478,7 +477,7 @@ def platform_data_links(name: str) -> str:
f"[YAML]({REPO_URL}/blob/main/platforms/{name}.yml)",
f"[JSON](../api/v1/platforms/{name}.json)",
]
if (REPO_ROOT / "install" / f"{name}.json").is_file():
if (siteinputs.manifests_dir() / f"{name}.json").is_file():
# The site's own copy, byte for byte (publish_manifests).
links.append(f"[install manifest](../api/v1/manifests/{name}.json)")
# The installed BIOS folder for clrmamepro and RomVault.
@@ -622,7 +621,7 @@ def core_folders_section(name: str, config: dict) -> list[str]:
folders come from its launch scripts, the files from its install manifest.
"""
folders = config.get("core_system_dirs") or {}
manifest = REPO_ROOT / "install" / f"{name}.json"
manifest = siteinputs.manifests_dir() / f"{name}.json"
files = json.loads(manifest.read_text())["files"] if manifest.is_file() else []
lines = [
"### Core folders",
+1 -1
View File
@@ -456,7 +456,7 @@ def _entry_archives(entry: dict, files: dict, by_name: dict) -> set[str]:
if sha1 not in files:
continue
if crcs:
held = zip_member_crcs(str(REPO_ROOT / files[sha1]["path"]))
held = zip_member_crcs(str(siteinputs.collection_path(files[sha1]["path"])))
# An archive the build cannot read keeps its name.
if held and not held & crcs:
continue
+2 -2
View File
@@ -7,12 +7,12 @@ import re
import urllib.parse
from pathlib import Path
from model import siteinputs
from model.collection import collection_paths
from model.systemnames import system_name
from sitegen import starlight as sitestarlight
from sitegen.cards import emulator_file_anchors
from sitegen.config import REPO_URL, SITE_NAME, SITE_URL
from core.paths import REPO_ROOT
from sitegen.descriptions import EMULATOR_SNIPPETS, NOTHING_TO_FETCH, PAGE_DATA, TITLE_NOUNS, title_noun
from sitegen.emulatorcards import snippet_noun
from sitegen.install import comes_with_app
@@ -56,7 +56,7 @@ def write_platform_dats(folder: Path, db: dict, members: dict, generated_at: str
folder.mkdir(parents=True, exist_ok=True)
digests = data_member_digests(members)
written = []
for source in sorted((REPO_ROOT / "install").glob("*.json")):
for source in sorted(siteinputs.manifests_dir().glob("*.json")):
manifest = json.loads(source.read_text(encoding="utf-8"))
path = folder / f"{source.stem}.dat"
write_if_changed(str(path), platform_dat(manifest, db, digests, generated_at))
+1 -2
View File
@@ -3,7 +3,6 @@
from __future__ import annotations
from model import releaserecord
from core.paths import REPO_ROOT
from core.sizes import size_text
from core.ziptools import build_zip_contents_index
from model import siteinputs
@@ -37,7 +36,7 @@ def build_file_consumers(db: dict, coverages: dict, profiles: dict) -> FileConsu
consumers = FileConsumers(db, build_zip_contents_index(db))
consumers.add_platforms({name: cov["config"] for name, cov in coverages.items()})
consumers.add_emulators(profiles)
consumers.add_manifests(REPO_ROOT / "install")
consumers.add_manifests(siteinputs.manifests_dir())
return consumers
+45
View File
@@ -55,6 +55,38 @@ class TheGivenDatabase(_Inputs):
self.use(db=self.db)
self.assertEqual(platformfiles._collection_sha1("bios/X/only-here.bin"), SHA1)
def test_collection_paths_and_manifests_sit_beside_the_given_database(self) -> None:
self.use(db=self.db)
self.assertEqual(siteinputs.collection_path("bios/X/only-here.bin"),
self.db.parent / "bios" / "X" / "only-here.bin")
self.assertEqual(siteinputs.manifests_dir(), self.db.parent / "install")
self.use(db=self.db, manifests=Path("/elsewhere/install"))
self.assertEqual(siteinputs.manifests_dir(), Path("/elsewhere/install"))
def test_the_platform_links_follow_the_given_manifests(self) -> None:
self.use(db=self.db)
self.assertNotIn("install manifest", platformfiles.platform_data_links("retroarch"))
(self.db.parent / "install").mkdir()
(self.db.parent / "install" / "retroarch.json").write_text("{}")
self.assertIn("install manifest", platformfiles.platform_data_links("retroarch"))
def test_board_election_opens_the_given_collection_archive(self) -> None:
import zipfile
from sitegen import render
archive = self.db.parent / "bios" / "X" / "board.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}"
files = {SHA1: {"path": "bios/X/board.zip"}}
entry = {"name": "board.zip", "contents": [{"crc32": crc}]}
self.use(db=self.db)
self.assertEqual(render._entry_archives(entry, files, {"board.zip": [SHA1]}), {SHA1})
other = {"name": "board.zip", "contents": [{"crc32": "deadbeef"}]}
self.assertEqual(render._entry_archives(other, files, {"board.zip": [SHA1]}), set())
class TheGivenProfilesAndPlatforms(_Inputs):
def setUp(self) -> None:
@@ -157,6 +189,19 @@ class NoPageModuleReadsTheRepositoryInputs(unittest.TestCase):
)
self.assertEqual(found, [])
def test_no_page_module_reads_the_repository_manifests(self) -> None:
modules = [SCRIPTS / "sitegen" / f"{name}.py"
for name in ("render", "platformfiles", "whichpack", "structured")]
found = [
f"{module.name}:{node.lineno}"
for module in modules
for node in ast.walk(ast.parse(module.read_text(encoding="utf-8")))
if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Div)
and getattr(node.left, "id", "") == "REPO_ROOT"
and isinstance(node.right, ast.Constant) and node.right.value == "install"
]
self.assertEqual(found, [])
def test_generate_installs_the_inputs_first(self) -> None:
build = (SCRIPTS / "sitegen" / "build.py").read_text(encoding="utf-8")
source = ast.get_source_segment(