fix: place install commands where systems link

system_install_choices and the emulator card's maker read the folder
votes of sitegen.places while every system link read system_section:
Game Boy Color's commands sat under Game Boy, Super A'Can's under
Arcade. Both now read system_section, after the boards are recorded,
and a test checks every command against its system's link.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 21:44:08 +01:00
1 parent 2971219571
commit 74924be233
9 files changed
+69 -104

No files matched your search

+3 -3
View File
@@ -262,10 +262,10 @@ def _write_system_pages(run: _SiteRun) -> None:
})
# The arcade boards are recorded before any page links one, the
# system pages first among them.
# system pages and their install commands first among them.
reset_console_pages()
sections, console_installs = arcade_board_sections(
manufacturers, system_install_choices(run.coverages))
sections = arcade_board_sections(manufacturers)
console_installs = system_install_choices(run.coverages)
linked, total = link_coverage(
system_ids(run.profiles, [cov["config"] for cov in run.coverages.values()]))
print(f" {linked} of {total} system ids linked")
+9 -8
View File
@@ -23,7 +23,7 @@ from model.mamerelease import tag_version
from sitegen.fields import search_excluded
from sitegen.install import manifest_systems, platform_display
from sitegen.render import (
SHORT_HASH, card_anchor, code_span, count_text, emulator_card_page, system_page_map,
SHORT_HASH, card_anchor, code_span, count_text, emulator_card_page, system_section,
)
@@ -750,18 +750,19 @@ def card_title(text: str, anchor: str, searchable: bool = True, weight: int = 10
def system_install_choices(coverages: dict) -> dict[str, dict[str, list[tuple[str, str]]]]:
"""slug -> console -> the (platform, system id) pairs linked to it.
Read through the same table as every system link, so a command sits in
the section the platform's system links to. Only a system the
platform's install manifest records is offered: --system refuses any
other name.
Placed by system_section, the answer every system link reads, so a
command sits in the section the platform's system links to: the folder
votes put Game Boy Color's under Game Boy and Super A'Can's under
Arcade. A system with no section (vgmplay, vvvvvv) links nowhere and
offers no command there. Call once the arcade boards are recorded, so a
board's systems reach the board's section. Only a system the platform's
install manifest records is offered: --system refuses any other name.
"""
from sitegen.render import page_by_norm
choices: dict[str, dict[str, list[tuple[str, str]]]] = {}
for name, cov in sorted(coverages.items()):
recorded = manifest_systems(name)
for sys_id in sorted(set(cov["config"].get("systems") or {}) & recorded):
page = system_page_map.get(sys_id) or page_by_norm(sys_id)
page = system_section(sys_id)
if page:
slug, console = page
choices.setdefault(slug, {}).setdefault(console, []).append((name, sys_id))
+1 -1
View File
@@ -1,4 +1,4 @@
"""Which system page each system id leads to, read from the collection's folders."""
"""Where the collection's folders place each system id: the run's set of system ids."""
from __future__ import annotations
+4 -31
View File
@@ -117,7 +117,9 @@ def system_icon_markdown(manufacturer: str, console_name: str) -> str:
return ""
return markup.image(console_name, _icon_url(name), width="24") + " "
# Global index: maps system_id -> (manufacturer_slug, console_name) for cross-linking
# The system ids the collection's folders place (sitegen.places), by the
# folder each is placed in. Read as the run's set of system ids: a link, an
# install command and a card's maker go where system_section() says.
system_page_map: dict[str, tuple[str, str]] = {}
def slugify_anchor(text: str) -> str:
@@ -130,39 +132,10 @@ def slugify_anchor(text: str) -> str:
slug = slug.strip("-")
return slug
_norm_page_map: dict[str, tuple[str, str] | None] = {}
def set_system_page_map(mapping: dict[str, tuple[str, str]]) -> None:
"""Install the system id -> page table every link on the site reads.
The table replaces the previous one, and the index of other spellings is
derived from it here. Kept anywhere else, it outlived a table of the same
size and linked to the pages of the previous one.
"""
from model.systems import norm_system_id
"""Install the run's placed system ids, replacing the previous table."""
system_page_map.clear()
system_page_map.update(mapping)
_norm_page_map.clear()
for known, page in system_page_map.items():
key = norm_system_id(known)
if _norm_page_map.get(key, page) != page:
_norm_page_map[key] = None
else:
_norm_page_map[key] = page
def page_by_norm(sys_id: str) -> tuple[str, str] | None:
"""The page an id leads to under another spelling of the same system.
Emulator cards name sega-megadrive or sinclair-zxspectrum, the pages are
keyed by the platforms' spellings: 2,431 of 4,195 cards had no link. A
spelling two pages share leads nowhere rather than to either.
"""
from model.systems import norm_system_id
return _norm_page_map.get(norm_system_id(sys_id))
# A manufacturer page too large for one page is a summary, each console on
+4 -2
View File
@@ -17,7 +17,7 @@ from sitegen.descriptions import EMULATOR_SNIPPETS, NOTHING_TO_FETCH, PAGE_DATA,
from sitegen.emulatorcards import snippet_noun
from sitegen.install import comes_with_app
from sitegen.lookup import data_member_digests, hash_pairs
from sitegen.render import card_anchor, system_page_map
from sitegen.render import card_anchor, system_section
from sitegen.write import write_if_changed
@@ -302,7 +302,9 @@ def record_emulator_page(name: str, profile: dict) -> None:
fetched = [f for f in listed if f.get("name") and not comes_with_app(f)]
systems = profile.get("systems") or []
first = systems[0] if systems else ""
makers = [system_page_map[sys_id][0] for sys_id in systems if sys_id in system_page_map]
# The maker of the section each system links to, as the system pages
# place it.
makers = [section[0] for section in (system_section(str(sid)) for sid in systems) if section]
if makers:
sitestarlight.EMULATOR_CARDS[f"emulators/{name}"] = makers[0]
else:
+7 -26
View File
@@ -137,30 +137,10 @@ class _BoardSort:
*(f for f in files if str(f.get("sha1", "")) not in held)]
def _installs_by_board(
installs: dict[str, dict[str, list[tuple[str, str]]]],
) -> dict[str, dict[str, list[tuple[str, str]]]]:
"""A system's install commands, moved to its board's section."""
from sitegen.render import system_section
moved: dict[str, dict[str, list[tuple[str, str]]]] = {}
for slug, consoles in installs.items():
for console, pairs in consoles.items():
for platform, sys_id in pairs:
section = system_section(sys_id)
if section and section[0] == "arcade" and section[1] in _BOARD_CONSOLES:
slug_to, console_to = section
else:
slug_to, console_to = slug, console
moved.setdefault(slug_to, {}).setdefault(console_to, []).append((platform, sys_id))
return moved
def arcade_board_sections(
manufacturers: dict[str, dict[str, list]],
installs: dict[str, dict[str, list[tuple[str, str]]]],
) -> tuple[dict[str, dict[str, list]], dict[str, dict[str, list[tuple[str, str]]]]]:
"""The Arcade page grouped by board, and each board's install commands.
) -> dict[str, dict[str, list]]:
"""The Arcade page grouped by board.
The Arcade sections were the folders of bios/Arcade/: NAOMI, PGM and
ZN-1 had no section, and their names stayed plain on 568 emulator
@@ -170,15 +150,16 @@ def arcade_board_sections(
copy. A set a reviewed machine owns (sitegen.render.archive_machine) goes
to that machine's section. Files neither claims stay in their
folders. Each board is recorded (sitegen.render.record_board_section) before
any page links one, and a system's install commands follow its link to
the board's section. Call after reset_console_pages()."""
any page links one, so the install commands placed after it
(sitegen.cards.system_install_choices) follow a system's link to the
board's section. Call after reset_console_pages()."""
from sitegen.render import arcade_boards, record_board_section
_BOARD_CONSOLES.clear()
_BOARDS_FROM.clear()
arcade = manufacturers.get("Arcade")
if not arcade:
return manufacturers, installs
return manufacturers
names = arcade_boards()
by_name = {name.casefold(): board for board, name in names.items()}
sort = _BoardSort()
@@ -191,7 +172,7 @@ def arcade_board_sections(
regrouped = {**sort.folders, **{names[board]: files for board, files in sort.boards.items()}}
makers = {mfr: {console: files for console, files in consoles.items() if files}
for mfr, consoles in sort.makers.items()}
return {**manufacturers, **makers, "Arcade": regrouped}, _installs_by_board(installs)
return {**manufacturers, **makers, "Arcade": regrouped}
def _boards_line(manufacturer: str, console: str) -> list[str]: