From 53d49bd002b2d3bdc003a60590ce58e6af3fc1a8 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:45:50 +0100 Subject: [PATCH] refactor: name release assets in largefiles only The dotted spelling, the download URL and the sha256 listing were rebuilt by release.assets, release.check and sitegen.cards. model.largefiles gives asset_spellings, asset_url, RELEASE_DOWNLOAD and digests_of. The release notes link is now URL-quoted like every other. --- scripts/model/largefiles.py | 43 +++++++++++++++++++++---------------- scripts/release/assets.py | 40 +++++++++++++--------------------- scripts/release/check.py | 3 +-- scripts/sitegen/cards.py | 11 ++-------- 4 files changed, 42 insertions(+), 55 deletions(-) diff --git a/scripts/model/largefiles.py b/scripts/model/largefiles.py index 0977e3b26..55f0e8abc 100644 --- a/scripts/model/largefiles.py +++ b/scripts/model/largefiles.py @@ -29,6 +29,7 @@ from core.paths import REPO_ROOT LARGE_FILES_RELEASE = "large-files" LARGE_FILES_REPO = "Abdess/retrobios" +RELEASE_DOWNLOAD = f"https://github.com/{LARGE_FILES_REPO}/releases/download/{LARGE_FILES_RELEASE}/" LARGE_FILES_CACHE = ".cache/large" # Verified revisions, hard-linked as / beside the cache. A name # in the cache is replaced when the release serves new bytes under it, so a @@ -85,7 +86,7 @@ def asset_names(registered: Iterable[str]) -> dict[str, str]: owners: dict[str, str] = {} for registered_path, name in names.items(): # GitHub publishes a space as a dot, so both spellings are taken. - for spelling in {name, name.replace(" ", ".")}: + for spelling in asset_spellings(name): other = owners.setdefault(spelling, registered_path) if other != registered_path: raise ValueError( @@ -105,6 +106,26 @@ def published_asset_name(name: str) -> str: return name.replace(" ", ".") +def asset_spellings(name: str) -> list[str]: + """Names the release may hold an asset under: as written, and as published.""" + published = published_asset_name(name) + return [name] if published == name else [name, published] + + +def asset_url(name: str) -> str: + """Download URL of the large-files release asset *name*.""" + return RELEASE_DOWNLOAD + urllib.parse.quote(name) + + +def digests_of(assets: Iterable[dict]) -> dict[str, str]: + """sha256 a release lists for each asset, by name.""" + return { + str(asset.get("name", "")): str(asset["digest"]).removeprefix("sha256:").lower() + for asset in assets + if str(asset.get("digest") or "").startswith("sha256:") + } + + def asset_candidates(name: str, registered: Iterable[str]) -> list[str]: """Assets that may hold *name*, a registered path or a bare file name. @@ -346,19 +367,7 @@ def _asset_urls(name: str) -> list[tuple[str, str]]: GitHub rewrites spaces to dots in release asset names, so a file whose name contains spaces is published under a dotted name. """ - candidates = [name] - if " " in name: - candidates.append(name.replace(" ", ".")) - return [ - ( - candidate, - ( - f"https://github.com/{LARGE_FILES_REPO}/releases/download/" - f"{LARGE_FILES_RELEASE}/{urllib.parse.quote(candidate)}" - ), - ) - for candidate in candidates - ] + return [(candidate, asset_url(candidate)) for candidate in asset_spellings(name)] def _read_once(path: str) -> tuple[dict[str, str], int, int] | None: @@ -428,11 +437,7 @@ def _served_digests() -> dict[str, str]: except (upstream.UpstreamError, ValueError) as exc: print(f" large files release listing: {exc}", file=sys.stderr) return {} - digests: dict[str, str] = {} - for asset in release.get("assets") or []: - digest = str(asset.get("digest") or "") - if digest.startswith("sha256:"): - digests[asset.get("name", "")] = digest.removeprefix("sha256:").lower() + digests = dict(digests_of(release.get("assets") or [])) _digests_cache = digests return digests diff --git a/scripts/release/assets.py b/scripts/release/assets.py index 2a79f5a6c..03342322d 100644 --- a/scripts/release/assets.py +++ b/scripts/release/assets.py @@ -14,7 +14,16 @@ from core.paths import EMULATORS_DIR from core.hashing import file_digest from core.sizes import size_text from model.composition import composition_tier -from model.largefiles import LARGE_FILES_RELEASE, LARGE_FILES_REPO, asset_names, registered_paths +from model.largefiles import ( + LARGE_FILES_RELEASE, + LARGE_FILES_REPO, + RELEASE_DOWNLOAD, + asset_names, + asset_spellings, + asset_url, + digests_of, + registered_paths, +) class AssetFinding(NamedTuple): @@ -36,15 +45,6 @@ def expected_assets(db: dict, gitignore_text: str) -> dict[str, int]: } -def _spellings(name: str) -> list[str]: - """Names the release may publish an asset under. - - GitHub rewrites spaces to dots in asset names, so a file whose name - carries spaces is published under the dotted form. - """ - return [name, name.replace(" ", ".")] if " " in name else [name] - - def compare( expected: dict[str, int], assets: dict[str, int], @@ -71,7 +71,7 @@ def compare( names = asset_names([*(registered or ()), *expected]) for path, size in sorted(expected.items()): served = next( - (name for name in _spellings(names[path]) if name in assets), None + (name for name in asset_spellings(names[path]) if name in assets), None ) if not served: findings.append(AssetFinding("missing", path, size, None)) @@ -97,16 +97,6 @@ def expected_digests(db: dict, gitignore_text: str) -> dict[str, str]: } -def digests_of(assets_json: list[dict]) -> dict[str, str]: - """sha256 the release lists for each asset, by name.""" - return { - a["name"]: str(a["digest"]).removeprefix("sha256:").lower() - for a in assets_json - if str(a.get("digest") or "").startswith("sha256:") - } - - -ASSET_URL = f"https://github.com/{LARGE_FILES_REPO}/releases/download/{LARGE_FILES_RELEASE}/" NOT_INDEXED = "Not indexed" SECTIONS = ( "Console firmware", @@ -181,7 +171,7 @@ def render_notes( for sha1, entry in db.get("files", {}).items(): path = entry.get("path", "") if path in names: - for candidate in _spellings(names[path]): + for candidate in asset_spellings(names[path]): indexed[candidate] = (sha1, path) rows: dict[str, list[tuple[int, str]]] = {section: [] for section in SECTIONS} @@ -200,7 +190,7 @@ def render_notes( sha1 = "" section = NOT_INDEXED description = description or name - link = f"[{name}]({ASSET_URL}{name})" + link = f"[{name}]({asset_url(name)})" if section == NOT_INDEXED: line = f"| {link} | {description} | {size_text(size)} |" else: @@ -256,8 +246,8 @@ def registry_bundles(registry_path: str = "platforms/_data_dirs.yml") -> dict[st if not isinstance(entry, dict): continue url = str(entry.get("source_url") or "") - if url.startswith(ASSET_URL): - bundles[url[len(ASSET_URL):]] = str(entry.get("description") or "") + if url.startswith(RELEASE_DOWNLOAD): + bundles[url.removeprefix(RELEASE_DOWNLOAD)] = str(entry.get("description") or "") return bundles diff --git a/scripts/release/check.py b/scripts/release/check.py index 324bdcde8..9a55592b2 100644 --- a/scripts/release/check.py +++ b/scripts/release/check.py @@ -6,8 +6,7 @@ import json import subprocess from dataclasses import dataclass -from release.assets import digests_of -from model.largefiles import LARGE_FILES_REPO +from model.largefiles import LARGE_FILES_REPO, digests_of SUMS = "SHA256SUMS.txt" diff --git a/scripts/sitegen/cards.py b/scripts/sitegen/cards.py index f4f6a6a25..6a7e47fe9 100644 --- a/scripts/sitegen/cards.py +++ b/scripts/sitegen/cards.py @@ -15,7 +15,6 @@ from core.hashing import parse_hash_list from model.collection import profiles_on_disk from packs.crossref import FileConsumers from sitegen import markup, wanted as sitewanted -from sitegen.config import REPO_URL from core.paths import REPO_ROOT from sitegen.fields import search_excluded from sitegen.install import platform_display @@ -134,16 +133,10 @@ def fetch_url(path: str) -> str: large-files release asset when .gitignore keeps it out of git.""" global _RELEASE_ASSET_NAMES if _RELEASE_ASSET_NAMES is None: - from model.largefiles import ( - LARGE_FILES_RELEASE, - asset_names, - load_registered_paths, - published_asset_name, - ) + from model.largefiles import asset_names, asset_url, load_registered_paths, published_asset_name _RELEASE_ASSET_NAMES = { - registered: f"{REPO_URL}/releases/download/{LARGE_FILES_RELEASE}/" - + urllib.parse.quote(published_asset_name(name)) + registered: asset_url(published_asset_name(name)) for registered, name in asset_names(load_registered_paths()).items() } return _RELEASE_ASSET_NAMES.get(path) or (