refactor: build the readme zip table in one place

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:03:14 +01:00
1 parent be63c6575a
commit 8db5bf6cf0
5 files changed
+66 -65

No files matched your search

+6 -5
View File
@@ -8,8 +8,7 @@ from resolve.nativemode import check_label
from sitegen import markup from sitegen import markup
from sitegen.guidepage import NO_ZIP_FAQ from sitegen.guidepage import NO_ZIP_FAQ
from sitegen.home import group_members from sitegen.home import group_members
from sitegen.install import has_release_pack from sitegen.readme import release_state, release_totals
from sitegen.readme import release_totals
# Platform pages # Platform pages
@@ -66,9 +65,11 @@ def setup_table(coverages: dict) -> list[str]:
] ]
for name, cov in sorted(coverages.items(), key=lambda item: item[1]["platform"].casefold()): for name, cov in sorted(coverages.items(), key=lambda item: item[1]["platform"].casefold()):
listed = f"{cov['total']:,}" if cov["total"] else "No list of its own" listed = f"{cov['total']:,}" if cov["total"] else "No list of its own"
files, _size = release_totals(name, releaserecord.load_advertised()) record = releaserecord.load_advertised()
zipped = (f"{files:,}" if files state = release_state(name, record)
else "No ZIP yet" if has_release_pack(name) else "No ZIP") files, _size = release_totals(name, record)
zipped = ("No ZIP" if state == "none" else "No ZIP yet" if state == "pending"
else f"{files:,}" if files else "-")
lines.append( lines.append(
f"| [{cov['platform']}](../platforms/{name}.md) | {listed} | {zipped} | " f"| [{cov['platform']}](../platforms/{name}.md) | {listed} | {zipped} | "
f"{check_label(cov['mode'], cov['config'].get('hash_rule'))} |" f"{check_label(cov['mode'], cov['config'].get('hash_rule'))} |"
+39 -46
View File
@@ -15,7 +15,7 @@ from devtools import prchecks
from model import releaserecord from model import releaserecord
from core.artifacts import write_if_changed from core.artifacts import write_if_changed
from core.cli import InputMissing from core.cli import InputMissing
from core.paths import DB_FILE, PLATFORMS_DIR, REPO_ROOT from core.paths import DB_FILE, REPO_ROOT
from core.sizes import size_text from core.sizes import size_text
from core.upstream import forge_headers from core.upstream import forge_headers
from installer_build.module import installer_module from installer_build.module import installer_module
@@ -30,7 +30,7 @@ from model.systems import system_index
from packs.coverage import verify_platform from packs.coverage import verify_platform
from resolve.cores import resolve_platform_cores from resolve.cores import resolve_platform_cores
from resolve.review import LARGE_FILE_ISSUE_URL from resolve.review import LARGE_FILE_ISSUE_URL
from sitegen.install import display_name, platform_display from sitegen.install import display_name, has_release_pack, platform_display
# The repository's profiles wherever the script is run from: a bare # The repository's profiles wherever the script is run from: a bare
@@ -240,6 +240,18 @@ def release_totals(platform_name: str, record: dict) -> tuple[int | None, int |
return pack["files"], pack["extracted_size"] return pack["files"], pack["extracted_size"]
def release_state(platform_name: str, record: dict) -> str:
""""none" for a setup no release publishes a ZIP for (`release_pack`),
"pending" for one the recorded release carries no pack for, added since,
else "released". No recorded tag, no release to be missing from."""
if not has_release_pack(platform_name):
return "none"
pack = releaserecord.pack_for(platform_name, record)
if record.get("tag") and not (pack and pack.get("assets")):
return "pending"
return "released"
NO_PACK = "Use the command" NO_PACK = "Use the command"
@@ -282,7 +294,7 @@ def asset_links(
def download_links( def download_links(
platform_name: str, record: dict, label: str, attrs: str = "", platform_name: str, record: dict, label: str, attrs: str = "",
button: Callable[[str, str], str] | None = None, button: Callable[[str, str], str] | None = None,
site: str = "", platforms_dir: str = PLATFORMS_DIR, page: str | None = None, site: str = "", page: str | None = None,
) -> str: ) -> str:
"""The download cell of a platform: its permanent get/ page. """The download cell of a platform: its permanent get/ page.
@@ -299,10 +311,10 @@ def download_links(
def link(text: str) -> str: def link(text: str) -> str:
return button(text, page) if button else f"[{text}]({page}){attrs}" return button(text, page) if button else f"[{text}]({page}){attrs}"
if (load_platform_registry(platforms_dir).get(platform_name) or {}).get("release_pack") is not True: state = release_state(platform_name, record)
if state == "none":
return link(NO_PACK) return link(NO_PACK)
pack = releaserecord.pack_for(platform_name, record) if state == "pending":
if record.get("tag") and not (pack and pack.get("assets")):
return f"No ZIP yet: {link(NO_PACK.lower())}" return f"No ZIP yet: {link(NO_PACK.lower())}"
return link(label) return link(label)
@@ -369,30 +381,31 @@ def download_table(
extract_paths: dict[str, str], extract_paths: dict[str, str],
record: dict, record: dict,
) -> list[str]: ) -> list[str]:
"""One row per platform: what its released pack holds and where it extracts.""" """The README's ZIP table: one row per setup the release carries a pack
for, then the sentence linking every other setup to its get/ page."""
by_name = sorted(coverages, key=lambda n: coverages[n]["platform"])
released = [name for name in by_name if release_totals(name, record)[0]]
lines = [ lines = [
"| Platform | Files | Extracted size | Extract to | Download |", "| Setup | Files | Size | Unzip into | Download |",
"|----------|------:|---------------:|-----------|----------|", "|-------|------:|-----:|------------|----------|",
] ]
for name, cov in sorted(coverages.items(), key=lambda x: x[1]["platform"]): for name in released:
files, size = release_totals(name, record) files, size = release_totals(name, record)
display = coverages[name]["platform"]
lines.append( lines.append(
f"| {cov['platform']} | {f'{files:,}' if files else '-'} |" f"| {display} | {files:,} | {size_text(size) if size else '-'} |"
f" {size_text(size) if size else '-'} |" f" {extract_paths.get(display, '')} |"
f" {extract_paths.get(cov['platform'], '')} |"
f" {download_links(name, record, 'Download', site=SITE_URL)} |" f" {download_links(name, record, 'Download', site=SITE_URL)} |"
) )
return lines others = [name for name in by_name if name not in released]
return [
*lines,
def no_pack_line() -> str: "",
"""Why some rows read "Use the command", in one sentence.""" "ZIPs are made for the setups most people download. The others install with the line"
return ( " above, and each page gives the command: "
"ZIPs are made for the setups most people download. The others read" + ", ".join(f"[{coverages[name]['platform']}]({SITE_URL}get/{name}/)" for name in others)
f" \"{NO_PACK}\": the installer above installs every file for them and" + ".",
" checks each one, and `--dry-run` shows what it would install" ]
f" ([why no ZIP]({SITE_URL}wiki/faq/#why-is-there-no-zip-for-my-setup))."
)
def _names_list(coverages: dict) -> str: def _names_list(coverages: dict) -> str:
@@ -598,8 +611,6 @@ def generate_readme(db: dict, platforms_dir: str, db_path: str = DB_FILE) -> str
# once carried (coverage, collection, build commands) are the site's. # once carried (coverage, collection, build commands) are the site's.
record = releaserecord.load_advertised(platforms_dir=platforms_dir) record = releaserecord.load_advertised(platforms_dir=platforms_dir)
extract_paths = _extract_cells(platforms_dir) extract_paths = _extract_cells(platforms_dir)
released = [name for name in sorted(coverages, key=lambda n: coverages[n]["platform"])
if release_totals(name, record)[0]]
lines = [ lines = [
'<p align="center">', '<p align="center">',
" <picture>", " <picture>",
@@ -663,25 +674,7 @@ def generate_readme(db: dict, platforms_dir: str, db_path: str = DB_FILE) -> str
"", "",
"The Files column counts what a pack holds once unzipped.", "The Files column counts what a pack holds once unzipped.",
"", "",
"| Setup | Files | Size | Unzip into | Download |", *download_table(coverages, extract_paths, record),
"|-------|------:|-----:|------------|----------|",
]
for name in released:
files, size = release_totals(name, record)
display = coverages[name]["platform"]
lines.append(
f"| {display} | {files:,} | {size_text(size) if size else '-'} |"
f" {extract_paths.get(display, '')} |"
f" {download_links(name, record, 'Download', site=SITE_URL)} |"
)
others = [name for name in sorted(coverages, key=lambda n: coverages[n]["platform"])
if name not in released]
lines.extend([
"",
"ZIPs are made for the setups most people download. The others install with the line"
" above, and each page gives the command: "
+ ", ".join(f"[{coverages[name]['platform']}]({SITE_URL}get/{name}/)" for name in others)
+ ".",
"", "",
"Unzip into the BIOS folder, files straight in it. A big pack comes in parts" "Unzip into the BIOS folder, files straight in it. A big pack comes in parts"
" (`Pack.part1of2.zip`): download every part" " (`Pack.part1of2.zip`): download every part"
@@ -726,7 +719,7 @@ def generate_readme(db: dict, platforms_dir: str, db_path: str = DB_FILE) -> str
"", "",
"</details>", "</details>",
"", "",
]) ]
contributors = fetch_contributors() contributors = fetch_contributors()
if not contributors: if not contributors:
+7 -9
View File
@@ -25,8 +25,8 @@ from sitegen.config import RELEASE_URL
from sitegen.guidepage import NO_ZIP_FAQ, devices_meta, first_screen_words, get_page_link from sitegen.guidepage import NO_ZIP_FAQ, devices_meta, first_screen_words, get_page_link
from sitegen.guides import fence, terminal_tabs, trust_box from sitegen.guides import fence, terminal_tabs, trust_box
from sitegen.home import group_keys, next_block, runs_on_text, setup_picker from sitegen.home import group_keys, next_block, runs_on_text, setup_picker
from sitegen.install import installer_module, has_release_pack, platform_display from sitegen.install import installer_module, platform_display
from sitegen.readme import NO_PACK, download_links from sitegen.readme import NO_PACK, download_links, release_state
# Build cross-reference indexes # Build cross-reference indexes
@@ -76,11 +76,11 @@ def _folder_cell(name: str, guide: Guide, prefix: str = "") -> str:
def _pack_cell(name: str, record: dict, prefix: str = "") -> str: def _pack_cell(name: str, record: dict, prefix: str = "") -> str:
"""The pack's parts and size, or the command where the release has none.""" """The pack's parts and size, or the command where the release has none."""
if not has_release_pack(name): state = release_state(name, record)
return f"No ZIP. [{NO_PACK}]({prefix}platforms/{name}.md#install)." if state != "released":
no_zip = "No ZIP yet" if state == "pending" else "No ZIP"
return f"{no_zip}. [{NO_PACK}]({prefix}platforms/{name}.md#install)."
pack = releaserecord.pack_for(name, record) pack = releaserecord.pack_for(name, record)
if record.get("tag") and not (pack and pack.get("assets")):
return f"No ZIP yet. [{NO_PACK}]({prefix}platforms/{name}.md#install)."
# One small button to the setup's get/ page, which lists every part, and # One small button to the setup's get/ page, which lists every part, and
# the size after it. # the size after it.
link = download_links(name, record, "ZIP", page=get_page_link(name, prefix), link = download_links(name, record, "ZIP", page=get_page_link(name, prefix),
@@ -233,9 +233,7 @@ def generate_which_pack() -> str:
*markup.details("note", "Every folder and ZIP in one table", *markup.details("note", "Every folder and ZIP in one table",
_folder_tables(registry, record, display)), _folder_tables(registry, record, display)),
] ]
pending = any(has_release_pack(key) and not (pack and pack.get("assets")) if any(release_state(key, record) == "pending" for key in registry):
for key, pack in ((key, releaserecord.pack_for(key, record)) for key in registry))
if record.get("tag") and pending:
lines += ["Setups added after the last release have no ZIP until the next one.", ""] lines += ["Setups added after the last release have no ZIP until the next one.", ""]
lines += ["No ZIP on a row: the command serves that setup. ZIPs are made for the " lines += ["No ZIP on a row: the command serves that setup. ZIPs are made for the "
f"setups most people download. [Why?]({NO_ZIP_FAQ})", ""] f"setups most people download. [Why?]({NO_ZIP_FAQ})", ""]
+11 -3
View File
@@ -26,6 +26,7 @@ from sitegen.readme import (
contributing_text, contributing_text,
download_links, download_links,
download_table, download_table,
release_state,
) )
REPO_ROOT = Path(__file__).resolve().parent.parent REPO_ROOT = Path(__file__).resolve().parent.parent
@@ -164,6 +165,12 @@ class DownloadLinksKeepTheirAddress(unittest.TestCase):
f"No ZIP yet: [use the command]({SITE_URL}get/retroarch/)", f"No ZIP yet: [use the command]({SITE_URL}get/retroarch/)",
) )
def test_no_zip_yet_needs_a_recorded_release(self):
self.assertEqual(release_state("retroarch", SPLIT_RECORD), "pending")
self.assertEqual(release_state("retroarch", {}), "released")
self.assertEqual(release_state("bizhawk", {}), "none")
self.assertEqual(release_state("romm", SPLIT_RECORD), "released")
def test_without_a_recorded_release_the_get_page_answers(self): def test_without_a_recorded_release_the_get_page_answers(self):
self.assertEqual( self.assertEqual(
download_links("romm", {}, "Download", site=SITE_URL), download_links("romm", {}, "Download", site=SITE_URL),
@@ -176,12 +183,13 @@ class DownloadLinksKeepTheirAddress(unittest.TestCase):
"bizhawk": {"platform": "BizHawk"}, "bizhawk": {"platform": "BizHawk"},
"romm": {"platform": "RomM"}, "romm": {"platform": "RomM"},
} }
rows = download_table(coverages, {}, SPLIT_RECORD)[2:] lines = download_table(coverages, {}, SPLIT_RECORD)
self.assertEqual(len(rows), 3) rows = [line for line in lines[2:] if line.startswith("|")]
self.assertEqual([row.split(" | ")[0] for row in rows], ["| Batocera", "| RomM"])
for row in rows: for row in rows:
self.assertNotIn("/releases/", row) self.assertNotIn("/releases/", row)
self.assertIn(f"{SITE_URL}get/", row) self.assertIn(f"{SITE_URL}get/", row)
self.assertIn("[Use the command]", next(r for r in rows if "BizHawk" in r)) self.assertIn(f"[BizHawk]({SITE_URL}get/bizhawk/)", lines[-1])
def test_the_generated_readme_links_every_get_page(self): def test_the_generated_readme_links_every_get_page(self):
if not RECORD.get("packs"): if not RECORD.get("packs"):
+3 -2
View File
@@ -401,9 +401,10 @@ class TheTableDescribesTheRelease(unittest.TestCase):
{"RetroArch": "`system/`"}, {"RetroArch": "`system/`"},
RECORD, RECORD,
) )
self.assertIn("| Platform | Files | Extracted size |", rows[0]) self.assertIn("| Setup | Files | Size | Unzip into |", rows[0])
self.assertIn("| RetroArch | 4,525 | 5.5 GB | `system/` |", rows[2]) self.assertIn("| RetroArch | 4,525 | 5.5 GB | `system/` |", rows[2])
self.assertIn("| Vita3K | - | - |", rows[3]) self.assertEqual(rows[3], "")
self.assertIn("get/vita3k/", rows[4])
def test_the_committed_record_is_the_one_the_readme_prints(self): def test_the_committed_record_is_the_one_the_readme_prints(self):
record_path = REPO_ROOT / "release.json" record_path = REPO_ROOT / "release.json"