fix: read the platform guides on first use

model.guides read and checked _registry.yml and _guides.yml at import,
from the repository: a pack build died on a registry entry without a guide
before parsing its options, and a site run on another platforms folder
took the repository's guides. The guides now load on first use, keyed on
siteinputs.current().platforms, behind accessor functions.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 21:02:46 +01:00
1 parent 9f987adb8c
commit e8b3cef5d5
31 files changed
+290 -204

No files matched your search

+69 -31
View File
@@ -2,22 +2,22 @@
from __future__ import annotations
import functools
import re
import textwrap
from dataclasses import dataclass, fields
from pathlib import Path
from model import siteinputs
from model.registry import load_platform_registry
from core.paths import REPO_ROOT
from model.sources import source_yaml
SH_NAME = "i"
PS1_NAME = "i.ps1"
PLATFORMS_DIR = REPO_ROOT / "platforms"
GUIDES_FILE = PLATFORMS_DIR / "_guides.yml"
GUIDES_NAME = "_guides.yml"
# The same installer from PyPI (scripts/build_pypi.py builds the package).
PACKAGE_COMMAND = "uvx retrobios"
class GuideError(ValueError):
@@ -182,7 +182,7 @@ def _folder_rows(value: object, extract_to: str, where: str) -> tuple[tuple[str,
def _guide(name: str, data: object, extract_to: str, terminals: dict) -> Guide:
where = f"{GUIDES_FILE.name}: guides.{name}"
where = f"{GUIDES_NAME}: guides.{name}"
if not isinstance(data, dict):
raise GuideError(f"{where}: expected a mapping")
_unknown(data, _GUIDE_KEYS, where)
@@ -336,7 +336,7 @@ def _group_tiles(raw: list, at: str) -> tuple[Tile, ...]:
return tuple(group_tiles)
def load_guides(path: Path = GUIDES_FILE, registry: dict | None = None) -> dict:
def load_guides(path: Path, registry: dict | None = None) -> dict:
"""The guides file, checked against the registry.
Every registered platform has a guide and a device group the file
@@ -344,7 +344,7 @@ def load_guides(path: Path = GUIDES_FILE, registry: dict | None = None) -> dict:
never built from half a guide.
"""
if registry is None:
registry = load_platform_registry(PLATFORMS_DIR, required=True)
registry = load_platform_registry(path.parent, required=True)
with open(path, encoding="utf-8") as handle:
data = source_yaml(handle) or {}
if not isinstance(data, dict):
@@ -404,32 +404,70 @@ def load_guides(path: Path = GUIDES_FILE, registry: dict | None = None) -> dict:
}
_LOADED = load_guides()
INSTALL_BASE: str = _LOADED["install_base"]
# The bootstraps the site serves (sitegen/bootstrap.py writes them).
INSTALL_SH: str = f"{INSTALL_BASE}/{SH_NAME}"
INSTALL_PS1: str = f"{INSTALL_BASE}/{PS1_NAME}"
# The same installer from PyPI (scripts/build_pypi.py builds the package).
PACKAGE_COMMAND = "uvx retrobios"
DEVICE_GROUPS: dict[str, tuple[str, str]] = _LOADED["device_groups"]
GROUP_ANCHORS: dict[str, str] = _LOADED["group_anchors"]
ALSO_RUNS: dict[str, tuple[tuple[str, str, str, str, str], ...]] = _LOADED["also_runs"]
GROUP_TILES: dict[str, tuple[Tile, ...]] = _LOADED["tiles"]
HANDHELD_GUIDE: HandheldGuide | None = _LOADED["handheld_guide"]
TERMINALS: dict[str, tuple[str, str, str]] = _LOADED["terminals"]
TRUST_ITEMS: tuple[str, ...] = _LOADED["trust_items"]
GUIDES: dict[str, Guide] = _LOADED["guides"]
_REGISTRY: dict = _LOADED["registry"]
@functools.cache
def _guides_in(platforms: Path) -> dict:
return load_guides(platforms / GUIDES_NAME)
def loaded() -> dict:
"""The guides of the platforms folder the run describes, read on first use."""
return _guides_in(siteinputs.current().platforms)
def platform_guides() -> dict[str, Guide]:
return loaded()["guides"]
def install_base() -> str:
return loaded()["install_base"]
def install_sh() -> str:
"""The sh bootstrap the site serves (sitegen/bootstrap.py writes it)."""
return f"{install_base()}/{SH_NAME}"
def install_ps1() -> str:
"""The PowerShell bootstrap the site serves."""
return f"{install_base()}/{PS1_NAME}"
def device_groups() -> dict[str, tuple[str, str]]:
return loaded()["device_groups"]
def group_anchors() -> dict[str, str]:
return loaded()["group_anchors"]
def also_runs() -> dict[str, tuple[tuple[str, str, str, str, str], ...]]:
return loaded()["also_runs"]
def group_tiles() -> dict[str, tuple[Tile, ...]]:
return loaded()["tiles"]
def handheld_guide() -> HandheldGuide | None:
return loaded()["handheld_guide"]
def terminals() -> dict[str, tuple[str, str, str]]:
return loaded()["terminals"]
def trust_items() -> tuple[str, ...]:
return loaded()["trust_items"]
def folder_list(name: str, registry: dict | None = None) -> list[tuple[str, str]]:
"""Every folder a guide names, as (where, path): the common ones, the
rarer builds, and the systems the registry detects when the guide says so."""
guide = GUIDES[name]
guide = platform_guides()[name]
rows = [*guide.folders, *guide.more_folders]
if guide.more_folders_detected:
rows += [(system, f"`{folder}`")
for system, folder in detected_systems(registry or _REGISTRY, name)]
for system, folder in detected_systems(registry or loaded()["registry"], name)]
return rows
@@ -442,12 +480,12 @@ def _plain_folders(name: str) -> str:
def setup_count() -> int:
"""Setups the site covers: every registered platform, since each keeps
its page, its pack and its command. The one count every page states."""
return len(GUIDES)
return len(platform_guides())
def pack_manual(name: str) -> str:
"""The manual part of a pack README, indented as the README is, or empty."""
guide = GUIDES.get(name)
guide = platform_guides().get(name)
if not guide or not guide.pack_manual:
return ""
text = guide.pack_manual.rstrip("\n")
@@ -465,7 +503,7 @@ def install_command(shell: str, args: str = "") -> str:
takes none.
"""
if shell == "sh":
return f"curl -fsSL {INSTALL_SH} | sh" + (f" -s -- {args}" if args else "")
return f"curl -fsSL {install_sh()} | sh" + (f" -s -- {args}" if args else "")
if args:
return f"&([scriptblock]::Create((irm {INSTALL_PS1}))) {args}"
return f"irm {INSTALL_PS1} | iex"
return f"&([scriptblock]::Create((irm {install_ps1()}))) {args}"
return f"irm {install_ps1()} | iex"
+9 -9
View File
@@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, TypedDict
from core.options import reject_unknown
from model.region import label as region_label
from model.guides import INSTALL_PS1, INSTALL_SH, pack_manual
from model.guides import install_ps1, install_sh, pack_manual
if TYPE_CHECKING:
from typing_extensions import Unpack
@@ -32,9 +32,9 @@ def _from_pack(platform_name: str, posix: bool, windows: bool,
lines = [" Already have this ZIP? Add --from-pack and its path: the files",
" come from it, not from the network. For a pack in parts, name one part.", ""]
if posix:
lines.append(f" curl -fsSL {INSTALL_SH} | sh -s -- {args} /path/to/pack.zip{dest[0]}")
lines.append(f" curl -fsSL {install_sh()} | sh -s -- {args} /path/to/pack.zip{dest[0]}")
if windows:
lines.append(f" &([scriptblock]::Create((irm {INSTALL_PS1}))) {args} C:\\path\\to\\pack.zip"
lines.append(f" &([scriptblock]::Create((irm {install_ps1()}))) {args} C:\\path\\to\\pack.zip"
f"{dest[1]}")
return [*lines, ""]
@@ -50,9 +50,9 @@ def _card_section(platform_name: str, display: str) -> str:
" ---------------------------------\n"
" With the SD card mounted on a computer, name its root with --dest.\n"
" Linux and macOS: run this in a terminal:\n\n"
f" curl -fsSL {INSTALL_SH} | sh -s -- --platform {platform_name} --dest /path/to/card\n\n"
f" curl -fsSL {install_sh()} | sh -s -- --platform {platform_name} --dest /path/to/card\n\n"
" Windows: run this in PowerShell (E: being the card):\n\n"
f" &([scriptblock]::Create((irm {INSTALL_PS1}))) --platform {platform_name} --dest E:\\\n\n"
f" &([scriptblock]::Create((irm {install_ps1()}))) --platform {platform_name} --dest E:\\\n\n"
f" The installer writes each file where {display} hands it to the core\n"
" and checks every file.\n\n"
+ "\n".join(_from_pack(platform_name, True, True, (" --dest /path/to/card", " --dest E:\\")))
@@ -100,9 +100,9 @@ def _automatic_section(
else:
labels = {"linux": "Linux", "darwin": "macOS"}
where = f"{' and '.join(labels[name] for name in posix)}: run this in a terminal:"
lines += [f" {where}", "", f" curl -fsSL {INSTALL_SH} | sh", ""]
lines += [f" {where}", "", f" curl -fsSL {install_sh()} | sh", ""]
if "windows" in systems:
lines += [" Windows: run this in PowerShell:", "", f" irm {INSTALL_PS1} | iex", ""]
lines += [" Windows: run this in PowerShell:", "", f" irm {install_ps1()} | iex", ""]
lines += [
f" The installer finds the {display} BIOS folder on this machine and",
" installs there, checking every file. --dest names another folder.",
@@ -119,9 +119,9 @@ def _automatic_section(
"",
]
if posix:
lines.append(f" curl -fsSL {INSTALL_SH} | sh -s -- --standalone-copies")
lines.append(f" curl -fsSL {install_sh()} | sh -s -- --standalone-copies")
if "windows" in systems:
lines.append(f" &([scriptblock]::Create((irm {INSTALL_PS1}))) --standalone-copies")
lines.append(f" &([scriptblock]::Create((irm {install_ps1()}))) --standalone-copies")
lines.append("")
return "\n".join(lines) + "\n"
+4 -3
View File
@@ -19,7 +19,7 @@ from model.collection import group_by_manufacturer, manufacturer_slug
from model.composition import compute_composition
from model.database import load_database
from model.dumpcatalog import load_provenance_snapshots
from model.guides import HANDHELD_GUIDE
from model.guides import handheld_guide
from model.profiles import is_emulator, lists_files, load_emulator_profiles
from model.registry import list_registered_platforms, load_platform_registry
from model.systemnames import program_names, set_console_sections, system_name
@@ -337,8 +337,9 @@ def _write_platform_pages(run: _SiteRun) -> dict[str, str]:
str(docs / "platforms" / "index.md"),
generate_platform_index(coverages, run.registry),
)
if HANDHELD_GUIDE:
write_if_changed(str(docs / HANDHELD_GUIDE.path), generate_handheld_guide(HANDHELD_GUIDE))
handhelds = handheld_guide()
if handhelds:
write_if_changed(str(docs / handhelds.path), generate_handheld_guide(handhelds))
published_parts = load_published_parts()
for name, cov in coverages.items():
# The emulators this platform runs, not every one of the system.
+5 -3
View File
@@ -8,7 +8,7 @@ from typing import TypeVar
from core.text import series
from model.collection import profiles_on_disk
from model.composition import GAME_DATA_TOPS
from model.guides import INSTALL_PS1, INSTALL_SH
from model.guides import install_ps1, install_sh
from model.profiles import entry_system_ids
from packs.consumers import FileConsumers
from sitegen.cards import emulator_display, romset_releases, system_file_card
@@ -41,14 +41,16 @@ SYSTEM_SUMMARY_HTML = 500_000
# bootstrap, 66 characters (67 for PowerShell). A box is weighed with its
# address at that length, so the shorter site address moves no console off
# or onto a summary and no card changes address.
FITTED_ADDRESS_CHARS = {INSTALL_PS1: 67, INSTALL_SH: 66}
FITTED_ADDRESS_CHARS = {"ps1": 67, "sh": 66}
def install_box_weight(lines: list[str]) -> int:
fitted_chars = {install_ps1(): FITTED_ADDRESS_CHARS["ps1"],
install_sh(): FITTED_ADDRESS_CHARS["sh"]}
weight = 0
for line in lines:
weight += len(line) + 1
for address, fitted in FITTED_ADDRESS_CHARS.items():
for address, fitted in fitted_chars.items():
found = line.count(address)
line = line.replace(address, "")
weight += found * (fitted - len(address))
+7 -5
View File
@@ -7,7 +7,7 @@ import re
from model import releaserecord
from model import siteinputs
from model.guides import DEVICE_GROUPS, GROUP_TILES, GUIDES, HANDHELD_GUIDE
from model.guides import device_groups, group_tiles, platform_guides, handheld_guide
from model.platforms import load_platform_config
from model.registry import load_platform_registry
from installer_build.handhelds import GROUP_PAGE
@@ -38,7 +38,8 @@ def _unzip_into(platform_name: str, display: str, extract_to: str | None, parts:
what = "them all" if parts > 1 else "it"
if not setup_relative(extract_to):
return [f"- Unzip {what} into {folder_words(display, extract_to)}.", ""]
lead = GUIDES[platform_name].lead if platform_name in GUIDES else ""
guide = platform_guides().get(platform_name)
lead = guide.lead if guide else ""
return [
f"- Unzip {what} into {folder_words(display, extract_to)}. "
f"[Where is it?](../platforms/{platform_name}.md#where-the-files-go)",
@@ -157,7 +158,8 @@ def generate_get_index() -> str:
"# BIOS files by setup", "",
"One page per setup. Its address stays the same, so it is the one to share.", "",
]
for group, (label, _description) in DEVICE_GROUPS.items():
handhelds = handheld_guide()
for group, (label, _description) in device_groups().items():
names = [name for name, entry in registry.items() if entry.get("device_group") == group]
if not names:
continue
@@ -167,8 +169,8 @@ def generate_get_index() -> str:
lines.append(f"- [{get_page_title(name, display)}]({name}.md)")
# The handheld app sits with the group whose tile leads to the
# handheld guide.
if any(HANDHELD_GUIDE and tile.link == HANDHELD_GUIDE.path
for tile in GROUP_TILES.get(group, ())):
if any(handhelds and tile.link == handhelds.path
for tile in group_tiles().get(group, ())):
lines.append(f"- [{sitehandheld.GROUP_TITLE}]({GROUP_PAGE}.md)")
lines.append("")
return "\n".join(lines)
+6 -6
View File
@@ -10,11 +10,11 @@ from model import releaserecord
from model import siteinputs
from model.collection import profiles_on_disk
from model.guides import (
GUIDES,
platform_guides,
Guide,
HandheldGuide,
HandheldSystem,
TERMINALS,
terminals,
detected_systems as _detected_systems,
)
from model.registry import load_platform_registry
@@ -258,7 +258,7 @@ def setup_routes(name: str, display: str, page_link: bool = False) -> list[str]:
computer, the card from a computer when the device has no network, and
the device's own terminal. *page_link* adds the get/ page, on the setup
page only."""
guide = GUIDES[name]
guide = platform_guides()[name]
share = _network_share(name, guide)
card = _card_route(name, display, guide)
shared = _get_page_line(name, display) if page_link else []
@@ -371,7 +371,7 @@ def _guide_install(name: str, guide: Guide, heading: str) -> list[str]:
"**E:**. Put the card's path after `--dest`.",
"",
]
device = guide.terminal or f"{TERMINALS['device'][1]} {DEVICE_TERMINAL_FALLBACK}"
device = guide.terminal or f"{terminals()['device'][1]} {DEVICE_TERMINAL_FALLBACK}"
return [
*lines,
*terminal_tabs(guide.run, platform_args(name, guide), how={"device": device}),
@@ -431,7 +431,7 @@ def generate_handheld_guide(guide: HandheldGuide) -> str:
A handheld owner starts from the device name. The systems were named
only in a closed note, with a path seen from inside the device."""
uses = GUIDES[guide.uses]
uses = platform_guides()[guide.uses]
display = platform_display(guide.uses)
args = {"windows": f"--platform {guide.uses} --dest E:\\BIOS",
"macos": f"--platform {guide.uses} --dest /path/to/card/BIOS",
@@ -479,7 +479,7 @@ def platform_guide(name: str, display: str, cov: dict, registry: dict, no_list:
A system that runs only on its own device puts the computer route
(download, unzip into the network folder) before the command."""
guide = GUIDES[name]
guide = platform_guides()[name]
entry = registry.get(name, {})
extract_to = entry.get("extract_to")
# An app's page opens on the command: one line to paste is the shortest
+3 -3
View File
@@ -13,7 +13,7 @@ from __future__ import annotations
from sitegen import markup
from model.guides import Guide, TERMINALS, TRUST_ITEMS, install_command
from model.guides import Guide, terminals, trust_items, install_command
# The title over each command block, by the shell it is written for.
@@ -42,7 +42,7 @@ def terminal_tabs(
after its text and after its command (sitegen.steps.install_box)."""
items = []
for key in tabs:
label, shared, shell = TERMINALS[key]
label, shared, shell = terminals()[key]
if len(tabs) == 1 and key in PLACES:
label = "" # one place, which the text around already names
text = (how or {}).get(key) or shared
@@ -70,7 +70,7 @@ def platform_args(name: str, guide: Guide) -> dict[str, str]:
def trust_box(prefix: str, indent: str = "") -> list[str]:
"""Is it safe, under every command on a guide page: the trust items."""
return markup.details("note", "Is it safe?", [
*(f"- {item}" for item in TRUST_ITEMS),
*(f"- {item}" for item in trust_items()),
"",
f"[Read the script first]({prefix}wiki/faq.md#is-piping-the-installer-into-a-shell-safe)",
], indent)
+7 -6
View File
@@ -7,7 +7,7 @@ import html
from core.paths import PLATFORMS_DIR
from core.sizes import size_text
from model.composition import compute_composition
from model.guides import DEVICE_GROUPS, GROUP_TILES, GUIDES, Guide, TRUST_ITEMS, setup_count
from model.guides import device_groups, group_tiles, platform_guides, Guide, trust_items, setup_count
from model.profiles import unique_emulator_profiles
from model.registry import load_platform_registry
from sitegen import markup
@@ -47,13 +47,14 @@ def _tiles(registry: dict, members: list[str], display: dict[str, str], prefix:
"""The setup tiles of one device group: logo, name and the hardware it
runs on, then the group's other tiles: a kind of device that runs one of
the setups (Android handhelds, Linux handhelds)."""
guides = platform_guides()
return markup.platform_tiles([
*((display[name], f"{prefix}platforms/{name}.md",
str(registry.get(name, {}).get("logo") or ""),
GUIDES[name].runs_on or runs_on_text(registry.get(name, {}), GUIDES[name]))
guides[name].runs_on or runs_on_text(registry.get(name, {}), guides[name]))
for name in members),
*((tile.name, f"{prefix}{tile.link}", tile.logo, tile.text)
for tile in GROUP_TILES.get(group, ())),
for tile in group_tiles().get(group, ())),
], eager=eager)
@@ -64,9 +65,9 @@ def setup_picker(registry: dict, display: dict[str, str], prefix: str = "") -> l
page: the 19 logos were most of the bytes of the home page."""
lines: list[str] = []
alone: list[str] = []
for group, (label, _description) in DEVICE_GROUPS.items():
for group, (label, _description) in device_groups().items():
members = group_keys(registry, group, display)
if len(members) == 1 and not GROUP_TILES.get(group):
if len(members) == 1 and not group_tiles().get(group):
alone += members
elif members:
eager = 0 if lines else markup.FIRST_ROW_TILES
@@ -136,7 +137,7 @@ def generate_home(
*setup_picker(registry, display),
"## Is it safe?",
"",
*(f"- {item}" for item in TRUST_ITEMS),
*(f"- {item}" for item in trust_items()),
"",
"[How the command is checked](wiki/faq.md#is-piping-the-installer-into-a-shell-safe). "
"Details: [Is it legal?](wiki/legal.md)",
+3 -3
View File
@@ -11,7 +11,7 @@ from pathlib import Path
from core.paths import DB_FILE, PLATFORMS_DIR, REPO_ROOT
from model.collection import group_by_manufacturer
from model.database import load_database
from model.guides import GROUP_TILES, GUIDES
from model.guides import group_tiles, platform_guides
from model.registry import load_platform_registry
from scraper.base_scraper import FetchError, fetch_bytes
from sitegen.imagenormalize import (
@@ -53,10 +53,10 @@ def fetch_logos() -> Iterator[tuple[str, str]]:
entries = []
# The tiles of a kind of device (Android handhelds) beside the setups
# carry a logo too, named after the tile.
sources = [(name, entry.get("logo"), entry, GUIDES.get(name))
sources = [(name, entry.get("logo"), entry, platform_guides().get(name))
for name, entry in sorted(platforms.items())]
sources += [(re.sub(r"[^a-z0-9]+", "-", tile.name.lower()).strip("-"), tile.logo, {}, tile)
for tiles in GROUP_TILES.values() for tile in tiles]
for tiles in group_tiles().values() for tile in tiles]
for name, url, entry, guide in sources:
if not url:
# No logo of its own: the tile shows initials, and an old copy
+12 -10
View File
@@ -13,7 +13,7 @@ from pathlib import Path
from core.text import series
from model import siteinputs
from model.collection import profiles_in
from model.guides import GUIDES, TERMINALS, install_command
from model.guides import platform_guides, terminals, install_command
from model.platforms import load_platform_config
from model.registry import list_release_pack_platforms
from model.profiles import reads_own_files
@@ -99,7 +99,7 @@ def install_commands(args: str = "", indent: str = "",
download page and the platform, system and emulator pages, so none of
them loses the Android or Windows form.
``oses`` names the terminals (keys of TERMINALS) the command runs in,
``oses`` names the terminals (keys of terminals()) the command runs in,
written as the synced OS tabs: MAME4droid runs on Android only, and its
page offered a PowerShell command. None keeps the three blocks.
"""
@@ -159,7 +159,7 @@ def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tu
standalone = profile.get("type") == "standalone"
accepted: dict[str, set[str]] = {}
for platform, names in _published_emulator_names().items():
if platform not in GUIDES:
if platform not in platform_guides():
continue
# Decided per setup, as the manifest decides it: Batocera's hcl
# package leaves out the 667 files every other setup's install brings.
@@ -167,7 +167,7 @@ def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tu
continue
if standalone and not runs_standalone(name, profile, _standalone_cores(platform)):
continue
if any("--dest" in args for args in platform_args(platform, GUIDES[platform]).values()):
if any("--dest" in args for args in platform_args(platform, platform_guides()[platform]).values()):
continue
own = {n for n, target in names.items() if target == name}
if own:
@@ -179,15 +179,16 @@ def emulator_install_route(name: str, profile: dict) -> tuple[str, list[str], tu
candidates = set().union(*accepted.values())
command = min(candidates, key=lambda n: (
-sum(n in own for own in accepted.values()), n != name, n))
order = list(GUIDES)
guides = platform_guides()
order = list(guides)
setups = sorted((p for p, own in accepted.items() if command in own), key=order.index)
terminals = {key for setup in setups for key in GUIDES[setup].run}
runs_in = {key for setup in setups for key in guides[setup].run}
if isinstance(profile.get("data_root"), dict):
# Only the systems the program is built for (Cemu has no Android
# build). A device setup runs it itself: its terminal stays.
terminals &= {"device", *(t for key in profile["data_root"]
runs_in &= {"device", *(t for key in profile["data_root"]
for t in _DATA_ROOT_TERMINALS.get(key, ()))}
oses = tuple(key for key in _COMMAND_TERMINALS if key in terminals)
oses = tuple(key for key in _COMMAND_TERMINALS if key in runs_in)
if not oses:
return "", [], ()
return command, setups, oses
@@ -452,7 +453,8 @@ def _default_setup(declared: list[tuple[str, str]]) -> tuple[str, str]:
most systems overall, then one the release publishes a ZIP for.
"""
def reach(pair: tuple[str, str]) -> tuple[int, int, bool]:
runs = GUIDES[pair[0]].run if pair[0] in GUIDES else ()
guide = platform_guides().get(pair[0])
runs = guide.run if guide else ()
return (len(set(runs) & set(INSTALL_PICKER_OSES)), len(runs), has_release_pack(pair[0]))
return max(declared, key=reach)
@@ -482,7 +484,7 @@ def _install_picker(declared: list[tuple[str, str]]) -> list[str]:
quote=False)
+ "</option>"
for platform, system in declared)
args = {key: _install_args(*lead, TERMINALS[key][2]) for key in INSTALL_PICKER_OSES}
args = {key: _install_args(*lead, terminals()[key][2]) for key in INSTALL_PICKER_OSES}
return [
"Each platform names the system its own way.",
"",
+6 -5
View File
@@ -8,7 +8,7 @@ from pathlib import Path
from model.collection import manufacturer_slug
from model.composition import GAME_DATA_TOPS
from model.guides import DEVICE_GROUPS, GROUP_TILES, HANDHELD_GUIDE
from model.guides import device_groups, group_tiles, handheld_guide
from model.profiles import unique_emulator_profiles
from sitegen import measurements as sitemeasurements, starlight as sitestarlight
from core.paths import REPO_ROOT
@@ -71,16 +71,17 @@ def _system_nav(manufacturers: dict) -> list:
def _platform_nav(coverages: dict, registry: dict) -> list:
"""Platforms by the kind of device they run on, as on the device picker."""
nav: list = ["platforms/index.md"]
for group, (label, _description) in DEVICE_GROUPS.items():
handhelds = handheld_guide()
for group, (label, _description) in device_groups().items():
members = [
{coverages[name]["platform"]: f"platforms/{name}.md"}
for name in sorted(coverages, key=lambda n: coverages[n]["platform"].casefold())
if registry.get(name, {}).get("device_group") == group
]
# The handheld guide sits with the group whose tile leads to it.
members += [{HANDHELD_GUIDE.title: HANDHELD_GUIDE.path}
for tile in GROUP_TILES.get(group, ())
if HANDHELD_GUIDE and tile.link == HANDHELD_GUIDE.path]
members += [{handhelds.title: handhelds.path}
for tile in group_tiles().get(group, ())
if handhelds and tile.link == handhelds.path]
if members:
nav.append({label: members})
return nav
+4 -4
View File
@@ -104,10 +104,10 @@ FENCE_TITLES = {"sh": "Terminal", "powershell": "PowerShell"}
def _installer_args(body: str) -> str:
"""The options of a one-line install command, continuation lines joined."""
from model.guides import INSTALL_SH
from model.guides import install_sh
line = " ".join(part.strip().rstrip("\\").strip() for part in body.splitlines())
match = re.fullmatch(rf"curl -fsSL {re.escape(INSTALL_SH)} \| sh(?: -s -- (.+))?", line)
match = re.fullmatch(rf"curl -fsSL {re.escape(install_sh())} \| sh(?: -s -- (.+))?", line)
if not match:
raise ValueError(f"an os-tabs block holds no install command: {line!r}")
return match.group(1) or ""
@@ -127,7 +127,7 @@ def expand_commands(markdown: str) -> str:
gives a tab its own options, for a folder that differs there."""
if "os-tabs" not in markdown:
return markdown
from model.guides import TERMINALS, install_command
from model.guides import terminals, install_command
def replace(match: re.Match[str]) -> str:
indent = match.group("indent")
@@ -135,7 +135,7 @@ def expand_commands(markdown: str) -> str:
own_args = _own_args(match.group("own"))
items = []
for key in OS_TAB_KEYS:
label, _how, shell = TERMINALS[key]
label, _how, shell = terminals()[key]
own = own_args.get(key) or args
items.append((label, [f'```{shell} title="{FENCE_TITLES[shell]}"',
install_command(shell, own), "```"]))
+4 -4
View File
@@ -3,7 +3,7 @@
from __future__ import annotations
from model import releaserecord
from model.guides import DEVICE_GROUPS, GROUP_TILES, GUIDES
from model.guides import device_groups, group_tiles, platform_guides
from resolve.nativemode import check_label
from sitegen import markup
from sitegen.guidepage import NO_ZIP_FAQ
@@ -25,7 +25,7 @@ def generate_platform_index(coverages: dict, registry: dict | None = None) -> st
"Each setup's page gives the folder and the command.",
"",
]
for group, (label, _description) in DEVICE_GROUPS.items():
for group, (label, _description) in device_groups().items():
members = group_members(coverages, registry, group)
if not members:
continue
@@ -34,10 +34,10 @@ def generate_platform_index(coverages: dict, registry: dict | None = None) -> st
# follow, as on the home tiles.
lines += [f"## {label}", ""]
lines += markup.card_grid([
*((f"[{coverages[name]['platform']}]({name}.md)", [GUIDES[name].summary])
*((f"[{coverages[name]['platform']}]({name}.md)", [platform_guides()[name].summary])
for name in members),
*((f"[{tile.name}](../{tile.link})", [tile.text])
for tile in GROUP_TILES.get(group, ())),
for tile in group_tiles().get(group, ())),
])
lines += [
f"Comparing setups? [Every setup side by side](../{SETUP_TABLE_LINK})",
+6 -5
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
import json
import re
from model.guides import GUIDES
from model.guides import platform_guides
from model.systemnames import system_name
from resolve.nativemode import check_label, reads_file_contents
from sitegen import markup
@@ -146,11 +146,12 @@ def _platform_head(name: str, cov: dict, registry: dict, no_list: bool) -> list[
"",
]
summary = GUIDES[name].summary if name in GUIDES else ""
guide = platform_guides().get(name)
summary = guide.summary if guide else ""
if summary:
lines += [summary + (f" [{display} website]({homepage})." if homepage else ""), ""]
if name in GUIDES:
if guide:
lines += platform_guide(name, display, cov, registry, no_list)
lines += [
"## Reference: every file by system { #reference-every-file-by-system }",
@@ -159,7 +160,7 @@ def _platform_head(name: str, cov: dict, registry: dict, no_list: bool) -> list[
"",
"For checking the work: counts, the list's source and each file's hashes.",
"",
*(line for note in (GUIDES[name].reference_notes if name in GUIDES else ())
*(line for note in (guide.reference_notes if guide else ())
for line in (note, "")),
]
if no_list:
@@ -197,7 +198,7 @@ def generate_platform_page(
"| Detail | Value |", "|---|---|"])
lines.extend(_platform_meta_rows(name, config, cov["mode"], registry))
lines.extend(["", "</div>"])
if name not in GUIDES:
if name not in platform_guides():
detect = (registry.get(name, {}).get("install") or {}).get("detect") or []
on_card = any(rule.get("method") == "card_marker" for rule in detect)
lines.extend(["", *platform_install_block(name, display, on_card)])
+2 -2
View File
@@ -419,7 +419,7 @@ def _check_get_pages(
"""
sys.path.insert(0, str(Path(__file__).resolve().parent))
from model import releaserecord
from model.guides import INSTALL_SH
from model.guides import install_sh
from model.registry import list_registered_platforms, list_release_pack_platforms
if not (platforms_dir / "_registry.yml").is_file():
@@ -444,7 +444,7 @@ def _check_get_pages(
packs = [a for a in assets if "_BIOS_Pack" in a]
if packs:
issues.append(f"{rel}: links a pack for a setup without one: {packs[0]}")
if f"{INSTALL_SH} | sh" not in (site / rel).read_text(encoding="utf-8"):
if f"{install_sh()} | sh" not in (site / rel).read_text(encoding="utf-8"):
issues.append(f"{rel}: gives no install command")
return issues
+12 -12
View File
@@ -7,13 +7,13 @@ from core.sizes import size_text
from core.ziptools import build_zip_contents_index
from model import siteinputs
from model.guides import (
ALSO_RUNS,
DEVICE_GROUPS,
GROUP_ANCHORS,
GUIDES,
also_runs,
device_groups,
group_anchors,
platform_guides,
Guide,
PACKAGE_COMMAND,
TERMINALS,
terminals,
install_command,
)
from model.platforms import load_platform_config
@@ -106,7 +106,7 @@ def _folder_row(key: str, display: dict[str, str], registry: dict, record: dict,
"""One setup's row: where it runs, its BIOS folder and its ZIP. A setup
whose ZIP holds its own top folder says where to unzip it, and the
BIOS folder itself when it has no ZIP to unzip."""
guide = GUIDES[key]
guide = platform_guides()[key]
pack = releaserecord.pack_for(key, record)
zipped = bool(pack and pack.get("assets"))
folder = (f"Unzip into `{own_root[key]}`" if key in own_root and zipped
@@ -124,23 +124,23 @@ def _folder_tables(registry: dict, record: dict, display: dict[str, str]) -> lis
header = ["| Setup | Runs on | BIOS folder | ZIP |", "|-------|---------|-------------|-----|"]
lines: list[str] = []
alone: list[str] = []
for group, (label, _description) in DEVICE_GROUPS.items():
for group, (label, _description) in device_groups().items():
members = group_keys(registry, group, display)
if len(members) == 1 and not ALSO_RUNS.get(group):
if len(members) == 1 and not also_runs().get(group):
alone += members
continue
if not members:
continue
lines += [f'<span id="{GROUP_ANCHORS[group]}"></span>**{label}**', "", *header]
lines += [f'<span id="{group_anchors()[group]}"></span>**{label}**', "", *header]
lines += [_folder_row(key, display, registry, record, own_root) for key in members]
lines += [
f"| {setup} | {runs_on} | {folder}, same as "
f"[{display[uses]}](platforms/{uses}.md) | {_pack_cell(uses, record)} |"
for setup, _summary, uses, runs_on, folder in ALSO_RUNS.get(group, ())
for setup, _summary, uses, runs_on, folder in also_runs().get(group, ())
]
lines.append("")
if alone:
anchors = "".join(f'<span id="{GROUP_ANCHORS[registry[key]["device_group"]]}"></span>'
anchors = "".join(f'<span id="{group_anchors()[registry[key]["device_group"]]}"></span>'
for key in alone)
lines += [f"{anchors}**Other setups**", "", *header,
*(_folder_row(key, display, registry, record, own_root) for key in alone), ""]
@@ -261,7 +261,7 @@ def generate_which_pack() -> str:
*trust_box(""),
"**Check the folder later.** Add `--check`. It changes nothing.",
"",
*terminal_tabs(all_tabs, dict.fromkeys(TERMINALS, "--check"), steps=False),
*terminal_tabs(all_tabs, dict.fromkeys(terminals(), "--check"), steps=False),
*markup.details("note", "Fill an SD card from a computer", [
"Name the setup and the BIOS folder on the card. For RetroArch on a "
"Nintendo Switch:",