refactor: move archive recipe counts out of cards

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 00:20:03 +01:00
1 parent 82cb80d554
commit 77513c2045
6 files changed
+37 -30

No files matched your search

+1
View File
@@ -145,6 +145,7 @@ on:
- "scripts/sitegen/agents.py"
- "scripts/sitegen/apiitems.py"
- "scripts/sitegen/arcadeboards.py"
- "scripts/sitegen/archivecounts.py"
- "scripts/sitegen/bootstrap.py"
- "scripts/sitegen/build.py"
- "scripts/sitegen/cards.py"
+31
View File
@@ -0,0 +1,31 @@
"""The generated block of wiki/archive-recipes.md: how many archives rebuild exact and canonical."""
from __future__ import annotations
import re
from pathlib import Path
from sitegen.render import WIKI_SRC_DIR
ARCHIVE_RECIPES_PAGE = Path(WIKI_SRC_DIR) / "archive-recipes.md"
_ARCHIVE_BLOCK = re.compile(
r"(<!-- generated: archive-recipes -->\n)(.*?)(<!-- /generated: archive-recipes -->)", re.S)
def archive_recipe_lines(counts: dict[str, int]) -> list[str]:
"""What an exact and a canonical rebuild are, each with its count."""
total = f"{counts['total']:,}"
return [
f"- **Exact**: the same bytes as the archive in the collection."
f" {counts['exact']:,} of {total} archives.",
f"- **Canonical**: the same files inside, packed another way."
f" {counts['canonical']:,} of {total} archives.",
]
def with_archive_counts(page: str, counts: dict[str, int]) -> str:
"""The archive recipes page with its counts read from recipes/archives.json."""
block = "\n".join(archive_recipe_lines(counts)) + "\n"
if not _ARCHIVE_BLOCK.search(page):
raise ValueError(f"{ARCHIVE_RECIPES_PAGE}: no archive-recipes block to write the counts in")
return _ARCHIVE_BLOCK.sub(lambda m: f"{m.group(1)}{block}{m.group(3)}", page, count=1)
+1 -2
View File
@@ -44,6 +44,7 @@ from sitegen import (
from sitegen.cards import wanted_link, system_install_choices, tables_out_of_search
from sitegen.config import GENERATED_DIRS, PUBLIC_DIRS, REPO_URL, yaml
from core.paths import REPO_ROOT
from sitegen.archivecounts import ARCHIVE_RECIPES_PAGE, with_archive_counts
from sitegen.crossref import generate_cross_reference
from sitegen.dataexports import (
source_commit,
@@ -57,10 +58,8 @@ from sitegen.pageregistry import PageRegistry
from sitegen.decorate import front_matter, decorate_markdown_pages
from sitegen.descriptions import title_noun
from sitegen.emulatorcards import (
ARCHIVE_RECIPES_PAGE,
ROMSET_FAQ_PAGE,
emulator_setups,
with_archive_counts,
with_romset_table,
)
from sitegen.emulatorpage import (
-24
View File
@@ -981,30 +981,6 @@ def with_romset_table(page: str, profiles: dict) -> str:
return _ROMSET_BLOCK.sub(lambda m: f"{m.group(1)}{table}{m.group(3)}", page, count=1)
ARCHIVE_RECIPES_PAGE = Path(WIKI_SRC_DIR) / "archive-recipes.md"
_ARCHIVE_BLOCK = re.compile(
r"(<!-- generated: archive-recipes -->\n)(.*?)(<!-- /generated: archive-recipes -->)", re.S)
def archive_recipe_lines(counts: dict[str, int]) -> list[str]:
"""What an exact and a canonical rebuild are, each with its count."""
total = f"{counts['total']:,}"
return [
f"- **Exact**: the same bytes as the archive in the collection."
f" {counts['exact']:,} of {total} archives.",
f"- **Canonical**: the same files inside, packed another way."
f" {counts['canonical']:,} of {total} archives.",
]
def with_archive_counts(page: str, counts: dict[str, int]) -> str:
"""The archive recipes page with its counts read from recipes/archives.json."""
block = "\n".join(archive_recipe_lines(counts)) + "\n"
if not _ARCHIVE_BLOCK.search(page):
raise ValueError(f"{ARCHIVE_RECIPES_PAGE}: no archive-recipes block to write the counts in")
return _ARCHIVE_BLOCK.sub(lambda m: f"{m.group(1)}{block}{m.group(3)}", page, count=1)
def render_metadata_rows(profile: dict) -> list[str]:
"""Scalar profile fields, one table row each.
+1 -1
View File
@@ -84,7 +84,7 @@ COMMANDS = {
"sitegen/startwith.py", "sitegen/systempages.py", "sitegen/emulatorcards.py",
"sitegen/emulatorpage.py", "sitegen/gaps.py", "sitegen/crossref.py", "sitegen/reference.py",
"sitegen/whichpack.py", "sitegen/nav.py", "sitegen/build.py", "sitegen/coverage.py",
"sitegen/extraction.py", "sitegen/releasepacks.py",
"sitegen/extraction.py", "sitegen/releasepacks.py", "sitegen/archivecounts.py",
"packs/crossref.py",
),
"sitediagrams.py": ("sitegen/diagrams.py",),
+3 -3
View File
@@ -663,12 +663,12 @@ class ArchiveRecipesAreCountedFromTheRecipes(unittest.TestCase):
self.assertIn(f"({SITE_URL}wiki/archive-recipes/)", line)
def test_the_page_counts(self) -> None:
from sitegen import emulatorcards
from sitegen import archivecounts
page = _read("wiki/archive-recipes.md")
self.assertEqual(emulatorcards.with_archive_counts(page, self.counts), page,
self.assertEqual(archivecounts.with_archive_counts(page, self.counts), page,
"wiki/archive-recipes.md counts are stale: run scripts/generate_site.py")
for line in emulatorcards.archive_recipe_lines(self.counts):
for line in archivecounts.archive_recipe_lines(self.counts):
self.assertIn(line, page)
def test_the_page_command_is_the_tools(self) -> None: