From 9a6003c22f2291643afeba9d3f8a21ebd35a0244 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:26:24 +0100 Subject: [PATCH] refactor: read the demo facts in demovariants --- .github/workflows/deploy-site.yml | 1 + scripts/sitegen/demovariants.py | 13 +++++++++++++ scripts/sitegen/home.py | 2 +- scripts/sitegen/readme.py | 15 +-------------- tests/test_site_demo.py | 6 +++--- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index 6b07ed6aa..197b36fff 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -144,6 +144,7 @@ on: - "scripts/sitegen/dataexports.py" - "scripts/sitegen/datapage.py" - "scripts/sitegen/decorate.py" + - "scripts/sitegen/demovariants.py" - "scripts/sitegen/descriptions.py" - "scripts/sitegen/diagrams.py" - "scripts/sitegen/emulatorcards.py" diff --git a/scripts/sitegen/demovariants.py b/scripts/sitegen/demovariants.py index 94a8a6e07..b20f65522 100644 --- a/scripts/sitegen/demovariants.py +++ b/scripts/sitegen/demovariants.py @@ -101,6 +101,19 @@ def load_facts() -> dict: return json.loads(FACTS.read_text(encoding="utf-8")) +def demo_facts(variant: str = "default") -> dict: + """What an installer demo shows, as make_demo.py measured it: one entry + per variant (default, handheld).""" + facts = json.loads(FACTS.read_text(encoding="utf-8")) + return facts[variant] + + +def demo_description(facts: dict | None = None) -> str: + """The demo in words, for a reader who cannot see it: the alt text + make_demo.py wrote from what it measured.""" + return str((facts or demo_facts())["alt"]) + + def write_facts(facts: dict) -> None: """demo.json, one entry per variant recorded so far, in VARIANTS order.""" ordered = {name: facts[name] for name in VARIANTS if name in facts} diff --git a/scripts/sitegen/home.py b/scripts/sitegen/home.py index 338f62fa7..6af0023b8 100644 --- a/scripts/sitegen/home.py +++ b/scripts/sitegen/home.py @@ -12,7 +12,7 @@ from model.profiles import unique_emulator_profiles from model.registry import load_platform_registry from sitegen import markup from sitegen.install import platform_display -from sitegen.readme import demo_description, demo_facts +from sitegen.demovariants import demo_description, demo_facts # Home page diff --git a/scripts/sitegen/readme.py b/scripts/sitegen/readme.py index 4cd06d2d7..661457769 100644 --- a/scripts/sitegen/readme.py +++ b/scripts/sitegen/readme.py @@ -27,6 +27,7 @@ from model.systems import system_index from resolve.review import LARGE_FILE_ISSUE_URL from sitegen.config import REPO_SLUG, REPO_URL, SITE_URL, UPLOAD_ROOT from sitegen.coverage import platform_coverages +from sitegen.demovariants import demo_description from sitegen.extraction import extract_targets from sitegen.releasepacks import download_links, release_totals @@ -91,7 +92,6 @@ def collection_line(total_files: int, comp: dict) -> str: # The installer demo (scripts/make_demo.py): the recording and what it shows. -DEMO_DIR = REPO_ROOT / "docs_assets" / "demo" DEMO_GIF = "docs_assets/demo/install.gif" REPO_PATH = "../.." REPO = REPO_SLUG @@ -123,19 +123,6 @@ def clone_line(db: dict) -> str: ) -def demo_facts(variant: str = "default") -> dict: - """What an installer demo shows, as make_demo.py measured it: one entry - per variant (default, handheld).""" - facts = json.loads((DEMO_DIR / "demo.json").read_text(encoding="utf-8")) - return facts[variant] - - -def demo_description(facts: dict | None = None) -> str: - """The demo in words, for a reader who cannot see it: the alt text - make_demo.py wrote from what it measured.""" - return str((facts or demo_facts())["alt"]) - - def _existing_contributor_block(readme_path: str = "README.md") -> list[str]: """The contributors already published, read back from the file. diff --git a/tests/test_site_demo.py b/tests/test_site_demo.py index d70376d31..bb8fbed4f 100644 --- a/tests/test_site_demo.py +++ b/tests/test_site_demo.py @@ -132,14 +132,14 @@ class TheTapeAndTheDriverAgree(unittest.TestCase): class TheReadmeShowsTheGif(unittest.TestCase): def test_the_gif_sits_under_the_commands_with_its_description(self): readme = (ROOT / "README.md").read_text(encoding="utf-8") - line = f"![{sitegen_readme.demo_description()}]({sitegen_readme.DEMO_GIF})" + line = f"![{demovariants.demo_description()}]({sitegen_readme.DEMO_GIF})" self.assertIn(line, readme) self.assertLess(readme.index("## Install in one line"), readme.index(line)) self.assertLess(readme.index(line), readme.index("## Or download a ZIP")) def test_the_description_names_what_the_recording_measured(self): facts = _facts() - words = sitegen_readme.demo_description(facts) + words = demovariants.demo_description(facts) for value in (facts["setup"], f"{facts['games']} games", f"{facts['files']} BIOS files", facts["size"]): self.assertIn(str(value), words) @@ -197,7 +197,7 @@ class TheTwoPagesShowIt(unittest.TestCase): from sitegen import home tag = home.install_demo()[0] - self.assertIn(f'description="{sitegen_readme.demo_description()}"', tag) + self.assertIn(f'description="{demovariants.demo_description()}"', tag) source = script_source("generate_site.py") body = source[source.index("def generate_home("):] body = body[:body.index("\ndef ", 1)]