mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 10:58:52 -06:00
refactor: move coverage and release out of readme
This commit is contained in:
1 parent
9521dd040a
commit
416299b6e0
19 files changed
+417
-384
No files matched your search
@@ -92,7 +92,7 @@ from sitegen.platformindex import SETUP_TABLE_PAGE, generate_platform_index, wit
|
||||
from sitegen.platformpage import own_list_only, generate_platform_page
|
||||
from sitegen.provenance import WantedDumps, generate_provenance_page, load_derivable, wanted_dumps
|
||||
from sitegen.publish import write_release_advertised
|
||||
from sitegen.readme import platform_coverages
|
||||
from sitegen.coverage import platform_coverages
|
||||
from sitegen.reference import (
|
||||
generate_contributing,
|
||||
generate_not_found,
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
"""Coverage of each platform as verify counts it, cached between the site and README builds."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
|
||||
from core.cli import InputMissing
|
||||
from core.paths import DB_FILE, EMULATORS_DIR, REPO_ROOT
|
||||
from model.largefiles import LARGE_FILES_CACHE
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.registry import VERSIONS_FILE
|
||||
from packs.coverage import verify_platform
|
||||
from packs.verdicts import blocking_missing
|
||||
from resolve.cores import resolve_platform_cores
|
||||
from sitegen.install import display_name
|
||||
|
||||
|
||||
# The repository's profiles wherever the script is run from: a bare
|
||||
# "emulators" read the working directory, and a run elsewhere counted 0 cores.
|
||||
_EMULATORS_DIR = str(REPO_ROOT / EMULATORS_DIR)
|
||||
|
||||
|
||||
def compute_coverage(
|
||||
platform_name: str,
|
||||
platforms_dir: str,
|
||||
db: dict,
|
||||
data_registry: dict | None = None,
|
||||
emulators_dir: str = _EMULATORS_DIR,
|
||||
) -> dict:
|
||||
config = load_platform_config(platform_name, platforms_dir)
|
||||
result = verify_platform(
|
||||
config,
|
||||
db,
|
||||
emulators_dir,
|
||||
data_dir_registry=data_registry,
|
||||
)
|
||||
sc = result.get("status_counts", {})
|
||||
ok = sc.get("ok", 0)
|
||||
untested = sc.get("untested", 0)
|
||||
missing = sc.get("missing", 0)
|
||||
total = result["total_files"]
|
||||
# An UNTESTED file the builder refuses (its declared hash contradicted on
|
||||
# a hash platform) is held, not packed.
|
||||
present = ok + untested - len(result.get("excluded_files", []))
|
||||
pct = (present / total * 100) if total > 0 else 0
|
||||
undeclared = result.get("undeclared_files", [])
|
||||
# Held is not packed: a file the platform has no folder for, or one below
|
||||
# a folder it lists flat, stays out of the pack the fraction describes.
|
||||
core_present = sum(
|
||||
1 for u in undeclared if u.get("in_repo") and u.get("in_pack", True)
|
||||
)
|
||||
core_missing = len(undeclared) - core_present
|
||||
# Files a profile marks unsourceable never reach the undeclared list, so
|
||||
# the gap they represent has to be counted back in.
|
||||
profiles = load_emulator_profiles(emulators_dir)
|
||||
unsourceable_names = {
|
||||
f.get("name", "")
|
||||
for emu in resolve_platform_cores(config, profiles)
|
||||
for f in (profiles.get(emu) or {}).get("files", []) or []
|
||||
if f.get("unsourceable")
|
||||
}
|
||||
core_unsourceable = len(unsourceable_names)
|
||||
missing_names = unsourceable_names | {
|
||||
u.get("name", "") for u in undeclared if not u.get("in_repo")
|
||||
}
|
||||
return {
|
||||
"platform": display_name(config, platform_name),
|
||||
"total": total,
|
||||
"verified": ok,
|
||||
"untested": untested,
|
||||
"missing": missing,
|
||||
"missing_not_firmware": {
|
||||
category: len(dests)
|
||||
for category, dests in (result.get("missing_not_firmware") or {}).items()
|
||||
},
|
||||
"present": present,
|
||||
"percentage": pct,
|
||||
"core_present": core_present,
|
||||
"core_missing": core_missing,
|
||||
"core_unsourceable": core_unsourceable,
|
||||
"missing_names": missing_names,
|
||||
"unsourceable_names": unsourceable_names,
|
||||
"pack_files": present + core_present,
|
||||
"total_missing": missing + core_missing,
|
||||
"mode": config.get("verification_mode", "existence"),
|
||||
# The gaps page badge: verify's count, never refiltered from details.
|
||||
"required_missing": blocking_missing(
|
||||
result["severity_counts"], result["verification_mode"]),
|
||||
"details": result["details"],
|
||||
"config": config,
|
||||
"ground_truth": result.get(
|
||||
"ground_truth_coverage",
|
||||
{"with_validation": 0, "platform_only": total, "total": total},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
# The site and the README read the same coverage: the first generator to run
|
||||
# stores it here and the second reads it back, instead of verifying every
|
||||
# platform twice (about a minute of the site build).
|
||||
COVERAGE_CACHE_DIR = REPO_ROOT / "tmp" / "coverage-cache"
|
||||
_COVERAGE_CACHE_FORMAT = "4"
|
||||
|
||||
|
||||
def _coverage_inputs(db_path: Path, platforms_dir: str, emulators_dir: str) -> str:
|
||||
"""A digest of everything coverage is computed from.
|
||||
|
||||
The database, the platform and emulator files, the code, the install
|
||||
manifests, the data directory revisions, the state of bios/ on disk, and
|
||||
what a release asset resolves to: the large-file cache and whether this
|
||||
run may download. A test run is offline with its own cache, and its
|
||||
result was read back by the next normal run (Lakka 534/535 for 535/535).
|
||||
A change to any of them computes the coverage again.
|
||||
"""
|
||||
import hashlib
|
||||
|
||||
digest = hashlib.sha256(_COVERAGE_CACHE_FORMAT.encode())
|
||||
|
||||
def add_file(path: Path) -> None:
|
||||
digest.update(str(path).encode() + b"\0")
|
||||
digest.update(path.read_bytes() if path.is_file() else b"<absent>")
|
||||
|
||||
add_file(db_path.resolve())
|
||||
for root, pattern in ((Path(platforms_dir), "*"), (Path(emulators_dir), "*.yml"),
|
||||
(REPO_ROOT / "scripts", "*.py"), (REPO_ROOT / "install", "*.json"),
|
||||
(REPO_ROOT / "recipes", "*.json")):
|
||||
for path in sorted(p for p in root.resolve().rglob(pattern) if p.is_file()):
|
||||
add_file(path)
|
||||
for path in (REPO_ROOT / ".gitignore", REPO_ROOT / "_mame_clones.json",
|
||||
REPO_ROOT / VERSIONS_FILE):
|
||||
add_file(path)
|
||||
digest.update(b"offline\0" + (b"1" if os.environ.get("RETROBIOS_OFFLINE") else b"0") + b"\n")
|
||||
large = Path(LARGE_FILES_CACHE).resolve()
|
||||
digest.update(str(large).encode() + b"\0")
|
||||
for path in sorted(large.glob("*")) if large.is_dir() else ():
|
||||
if path.is_file():
|
||||
stat = path.stat()
|
||||
digest.update(f"{path.name}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode())
|
||||
bios = REPO_ROOT / "bios"
|
||||
for path in sorted(bios.rglob("*")):
|
||||
if path.is_file():
|
||||
stat = path.stat()
|
||||
digest.update(f"{path.relative_to(bios)}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode())
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def platform_coverages(
|
||||
platform_names: list[str],
|
||||
platforms_dir: str,
|
||||
db: dict,
|
||||
data_registry: dict | None = None,
|
||||
emulators_dir: str = _EMULATORS_DIR,
|
||||
db_path: str = DB_FILE,
|
||||
report: Callable[[str, dict], None] | None = None,
|
||||
) -> dict[str, dict]:
|
||||
"""compute_coverage for each platform, read from the cache when its
|
||||
inputs have not changed since a generator last stored it.
|
||||
|
||||
A platform with no YAML is left out, as compute_coverage raises for it.
|
||||
``report`` is called with each platform and its coverage.
|
||||
"""
|
||||
# pickle, not JSON: the coverage holds sets and enums that JSON would
|
||||
# turn into lists and strings. The file is written by this function into
|
||||
# the repository's own tmp/, never downloaded.
|
||||
import pickle
|
||||
|
||||
key = _coverage_inputs(Path(db_path), platforms_dir, emulators_dir)
|
||||
names = sorted(platform_names)
|
||||
cache = COVERAGE_CACHE_DIR / f"{key}.pickle"
|
||||
coverages: dict[str, dict] | None = None
|
||||
if cache.is_file():
|
||||
try:
|
||||
with cache.open("rb") as handle:
|
||||
stored = pickle.load(handle)
|
||||
except (OSError, EOFError, pickle.UnpicklingError) as exc:
|
||||
print(f" coverage cache unreadable, computing again: {exc}", file=sys.stderr)
|
||||
else:
|
||||
if stored.get("platforms") == names:
|
||||
coverages = stored["coverages"]
|
||||
print(f" coverage read from {cache.relative_to(REPO_ROOT)}")
|
||||
if coverages is None:
|
||||
coverages = {}
|
||||
for name in names:
|
||||
try:
|
||||
coverages[name] = compute_coverage(
|
||||
name, platforms_dir, db, data_registry, emulators_dir=emulators_dir,
|
||||
)
|
||||
except InputMissing:
|
||||
# A missing profile or platform directory is no platform
|
||||
# left out: it emptied every one and cached the result.
|
||||
raise
|
||||
except FileNotFoundError as exc:
|
||||
print(f" {name}: skipped ({exc})", file=sys.stderr)
|
||||
COVERAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
scratch = cache.with_suffix(f".{os.getpid()}.tmp")
|
||||
with scratch.open("wb") as handle:
|
||||
pickle.dump({"platforms": names, "coverages": coverages}, handle,
|
||||
protocol=pickle.HIGHEST_PROTOCOL)
|
||||
scratch.replace(cache)
|
||||
# generate_site and generate_readme both purge here. One unlinking
|
||||
# what the other had just listed ended it on FileNotFoundError.
|
||||
for stale in COVERAGE_CACHE_DIR.glob("*.pickle"):
|
||||
if stale != cache:
|
||||
stale.unlink(missing_ok=True)
|
||||
ordered = {name: coverages[name] for name in platform_names if name in coverages}
|
||||
if report:
|
||||
for name in names:
|
||||
if name in ordered:
|
||||
report(name, ordered[name])
|
||||
return ordered
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Where each platform's pack extracts, and the packs that carry their own root folder."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from model.declarations import declared_root
|
||||
from model.platforms import load_platform_config
|
||||
from model.registry import load_platform_registry
|
||||
from sitegen.install import display_name, platform_display
|
||||
|
||||
|
||||
def extract_targets(platforms_dir: str) -> list[tuple[str, str]]:
|
||||
"""(display name, folder) per registered platform, where its pack extracts.
|
||||
|
||||
Read from the registry so the README, the site and the pack guide answer
|
||||
from one place. Sorted by display name.
|
||||
"""
|
||||
rows = [
|
||||
(platform_display(key, platforms_dir), entry["extract_to"])
|
||||
for key, entry in load_platform_registry(platforms_dir).items()
|
||||
if entry.get("extract_to")
|
||||
]
|
||||
return sorted(rows, key=lambda row: row[0].casefold())
|
||||
|
||||
|
||||
def own_root(config: dict) -> str:
|
||||
"""The folder a pack written from an empty base_destination starts with.
|
||||
|
||||
RetroDECK writes bios/ in front of its files, the MinUI family hands its
|
||||
cores folders below Bios/.
|
||||
"""
|
||||
root = declared_root(config)
|
||||
if root:
|
||||
return root
|
||||
tops = {directory.split("/", 1)[0] for directory in config.get("core_system_dirs") or {}}
|
||||
return tops.pop() if len(tops) == 1 else "bios"
|
||||
|
||||
|
||||
def extract_notes(platforms_dir: str, released_only: bool = False) -> list[str]:
|
||||
"""A pack whose entries carry their own root extracts above the BIOS folder.
|
||||
|
||||
*released_only* keeps the platforms a release publishes a pack for.
|
||||
"""
|
||||
folders = dict(extract_targets(platforms_dir))
|
||||
registry = load_platform_registry(platforms_dir)
|
||||
notes = []
|
||||
for key in sorted(registry):
|
||||
if released_only and registry[key].get("release_pack") is not True:
|
||||
continue
|
||||
config = load_platform_config(key, platforms_dir)
|
||||
display = display_name(config, key)
|
||||
if config.get("base_destination") == "" and display in folders:
|
||||
notes.append(
|
||||
f"The {display} pack holds its own `{own_root(config)}/` folder."
|
||||
f" Unzip it into `{folders[display]}`."
|
||||
)
|
||||
return notes
|
||||
@@ -27,7 +27,7 @@ from sitegen.guidepage import (
|
||||
from sitegen.home import next_block
|
||||
from sitegen.install import display_name, has_release_pack, platform_display
|
||||
from sitegen.parts import parent_front_matter
|
||||
from sitegen.readme import asset_links
|
||||
from sitegen.releasepacks import asset_links
|
||||
from sitegen.versions import release_line, version_line
|
||||
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ from core.sizes import size_text
|
||||
from sitegen.guides import platform_args, terminal_tabs
|
||||
from sitegen.home import next_block
|
||||
from sitegen.install import installer_module, has_release_pack, platform_display
|
||||
from sitegen.readme import download_links, extract_notes
|
||||
from sitegen.extraction import extract_notes
|
||||
from sitegen.releasepacks import download_links
|
||||
from sitegen.versions import release_line, setup_version, version_line
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from resolve.nativemode import check_label
|
||||
from sitegen import markup
|
||||
from sitegen.guidepage import NO_ZIP_FAQ
|
||||
from sitegen.home import group_members
|
||||
from sitegen.readme import release_state, release_totals
|
||||
from sitegen.releasepacks import release_state, release_totals
|
||||
|
||||
|
||||
# Platform pages
|
||||
|
||||
+5
-347
@@ -8,369 +8,27 @@ import re
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from core.text import series
|
||||
from romrecipes import ledger
|
||||
from devtools import prchecks
|
||||
from model import releaserecord
|
||||
from core.artifacts import write_if_changed
|
||||
from core.cli import InputMissing
|
||||
from core.paths import DB_FILE, REPO_ROOT
|
||||
from core.sizes import size_text
|
||||
from core import upstream
|
||||
from installer_build.module import installer_module
|
||||
from model.composition import compute_composition, count_catalog_matched
|
||||
from model.declarations import declared_root
|
||||
from model.guides import PACKAGE_COMMAND, install_command
|
||||
from model.largefiles import LARGE_FILES_CACHE, load_registered_paths
|
||||
from model.platforms import load_platform_config
|
||||
from model.largefiles import load_registered_paths
|
||||
from model.profiles import load_emulator_profiles, unique_emulator_profiles
|
||||
from model.registry import VERSIONS_FILE, list_registered_platforms, load_platform_registry
|
||||
from model.registry import list_registered_platforms
|
||||
from model.systems import system_index
|
||||
from packs.coverage import verify_platform
|
||||
from packs.verdicts import blocking_missing
|
||||
from resolve.cores import resolve_platform_cores
|
||||
from resolve.review import LARGE_FILE_ISSUE_URL
|
||||
from sitegen.config import REPO_SLUG, REPO_URL, SITE_URL, UPLOAD_ROOT
|
||||
from sitegen.install import display_name, has_release_pack, platform_display
|
||||
|
||||
|
||||
# The repository's profiles wherever the script is run from: a bare
|
||||
# "emulators" read the working directory, and a run elsewhere counted 0 cores.
|
||||
_EMULATORS_DIR = str(REPO_ROOT / "emulators")
|
||||
|
||||
|
||||
def compute_coverage(
|
||||
platform_name: str,
|
||||
platforms_dir: str,
|
||||
db: dict,
|
||||
data_registry: dict | None = None,
|
||||
emulators_dir: str = _EMULATORS_DIR,
|
||||
) -> dict:
|
||||
config = load_platform_config(platform_name, platforms_dir)
|
||||
result = verify_platform(
|
||||
config,
|
||||
db,
|
||||
emulators_dir,
|
||||
data_dir_registry=data_registry,
|
||||
)
|
||||
sc = result.get("status_counts", {})
|
||||
ok = sc.get("ok", 0)
|
||||
untested = sc.get("untested", 0)
|
||||
missing = sc.get("missing", 0)
|
||||
total = result["total_files"]
|
||||
# An UNTESTED file the builder refuses (its declared hash contradicted on
|
||||
# a hash platform) is held, not packed.
|
||||
present = ok + untested - len(result.get("excluded_files", []))
|
||||
pct = (present / total * 100) if total > 0 else 0
|
||||
undeclared = result.get("undeclared_files", [])
|
||||
# Held is not packed: a file the platform has no folder for, or one below
|
||||
# a folder it lists flat, stays out of the pack the fraction describes.
|
||||
core_present = sum(
|
||||
1 for u in undeclared if u.get("in_repo") and u.get("in_pack", True)
|
||||
)
|
||||
core_missing = len(undeclared) - core_present
|
||||
# Files a profile marks unsourceable never reach the undeclared list, so
|
||||
# the gap they represent has to be counted back in.
|
||||
profiles = load_emulator_profiles(emulators_dir)
|
||||
unsourceable_names = {
|
||||
f.get("name", "")
|
||||
for emu in resolve_platform_cores(config, profiles)
|
||||
for f in (profiles.get(emu) or {}).get("files", []) or []
|
||||
if f.get("unsourceable")
|
||||
}
|
||||
core_unsourceable = len(unsourceable_names)
|
||||
missing_names = unsourceable_names | {
|
||||
u.get("name", "") for u in undeclared if not u.get("in_repo")
|
||||
}
|
||||
return {
|
||||
"platform": display_name(config, platform_name),
|
||||
"total": total,
|
||||
"verified": ok,
|
||||
"untested": untested,
|
||||
"missing": missing,
|
||||
"missing_not_firmware": {
|
||||
category: len(dests)
|
||||
for category, dests in (result.get("missing_not_firmware") or {}).items()
|
||||
},
|
||||
"present": present,
|
||||
"percentage": pct,
|
||||
"core_present": core_present,
|
||||
"core_missing": core_missing,
|
||||
"core_unsourceable": core_unsourceable,
|
||||
"missing_names": missing_names,
|
||||
"unsourceable_names": unsourceable_names,
|
||||
"pack_files": present + core_present,
|
||||
"total_missing": missing + core_missing,
|
||||
"mode": config.get("verification_mode", "existence"),
|
||||
# The gaps page badge: verify's count, never refiltered from details.
|
||||
"required_missing": blocking_missing(
|
||||
result["severity_counts"], result["verification_mode"]),
|
||||
"details": result["details"],
|
||||
"config": config,
|
||||
"ground_truth": result.get(
|
||||
"ground_truth_coverage",
|
||||
{"with_validation": 0, "platform_only": total, "total": total},
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
# The site and the README read the same coverage: the first generator to run
|
||||
# stores it here and the second reads it back, instead of verifying every
|
||||
# platform twice (about a minute of the site build).
|
||||
COVERAGE_CACHE_DIR = REPO_ROOT / "tmp" / "coverage-cache"
|
||||
_COVERAGE_CACHE_FORMAT = "4"
|
||||
|
||||
|
||||
def _coverage_inputs(db_path: Path, platforms_dir: str, emulators_dir: str) -> str:
|
||||
"""A digest of everything coverage is computed from.
|
||||
|
||||
The database, the platform and emulator files, the code, the install
|
||||
manifests, the data directory revisions, the state of bios/ on disk, and
|
||||
what a release asset resolves to: the large-file cache and whether this
|
||||
run may download. A test run is offline with its own cache, and its
|
||||
result was read back by the next normal run (Lakka 534/535 for 535/535).
|
||||
A change to any of them computes the coverage again.
|
||||
"""
|
||||
import hashlib
|
||||
|
||||
digest = hashlib.sha256(_COVERAGE_CACHE_FORMAT.encode())
|
||||
|
||||
def add_file(path: Path) -> None:
|
||||
digest.update(str(path).encode() + b"\0")
|
||||
digest.update(path.read_bytes() if path.is_file() else b"<absent>")
|
||||
|
||||
add_file(db_path.resolve())
|
||||
for root, pattern in ((Path(platforms_dir), "*"), (Path(emulators_dir), "*.yml"),
|
||||
(REPO_ROOT / "scripts", "*.py"), (REPO_ROOT / "install", "*.json"),
|
||||
(REPO_ROOT / "recipes", "*.json")):
|
||||
for path in sorted(p for p in root.resolve().rglob(pattern) if p.is_file()):
|
||||
add_file(path)
|
||||
for path in (REPO_ROOT / ".gitignore", REPO_ROOT / "_mame_clones.json",
|
||||
REPO_ROOT / VERSIONS_FILE):
|
||||
add_file(path)
|
||||
digest.update(b"offline\0" + (b"1" if os.environ.get("RETROBIOS_OFFLINE") else b"0") + b"\n")
|
||||
large = Path(LARGE_FILES_CACHE).resolve()
|
||||
digest.update(str(large).encode() + b"\0")
|
||||
for path in sorted(large.glob("*")) if large.is_dir() else ():
|
||||
if path.is_file():
|
||||
stat = path.stat()
|
||||
digest.update(f"{path.name}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode())
|
||||
bios = REPO_ROOT / "bios"
|
||||
for path in sorted(bios.rglob("*")):
|
||||
if path.is_file():
|
||||
stat = path.stat()
|
||||
digest.update(f"{path.relative_to(bios)}\0{stat.st_size}\0{stat.st_mtime_ns}\n".encode())
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def platform_coverages(
|
||||
platform_names: list[str],
|
||||
platforms_dir: str,
|
||||
db: dict,
|
||||
data_registry: dict | None = None,
|
||||
emulators_dir: str = _EMULATORS_DIR,
|
||||
db_path: str = DB_FILE,
|
||||
report: Callable[[str, dict], None] | None = None,
|
||||
) -> dict[str, dict]:
|
||||
"""compute_coverage for each platform, read from the cache when its
|
||||
inputs have not changed since a generator last stored it.
|
||||
|
||||
A platform with no YAML is left out, as compute_coverage raises for it.
|
||||
``report`` is called with each platform and its coverage.
|
||||
"""
|
||||
# pickle, not JSON: the coverage holds sets and enums that JSON would
|
||||
# turn into lists and strings. The file is written by this function into
|
||||
# the repository's own tmp/, never downloaded.
|
||||
import pickle
|
||||
|
||||
key = _coverage_inputs(Path(db_path), platforms_dir, emulators_dir)
|
||||
names = sorted(platform_names)
|
||||
cache = COVERAGE_CACHE_DIR / f"{key}.pickle"
|
||||
coverages: dict[str, dict] | None = None
|
||||
if cache.is_file():
|
||||
try:
|
||||
with cache.open("rb") as handle:
|
||||
stored = pickle.load(handle)
|
||||
except (OSError, EOFError, pickle.UnpicklingError) as exc:
|
||||
print(f" coverage cache unreadable, computing again: {exc}", file=sys.stderr)
|
||||
else:
|
||||
if stored.get("platforms") == names:
|
||||
coverages = stored["coverages"]
|
||||
print(f" coverage read from {cache.relative_to(REPO_ROOT)}")
|
||||
if coverages is None:
|
||||
coverages = {}
|
||||
for name in names:
|
||||
try:
|
||||
coverages[name] = compute_coverage(
|
||||
name, platforms_dir, db, data_registry, emulators_dir=emulators_dir,
|
||||
)
|
||||
except InputMissing:
|
||||
# A missing profile or platform directory is no platform
|
||||
# left out: it emptied every one and cached the result.
|
||||
raise
|
||||
except FileNotFoundError as exc:
|
||||
print(f" {name}: skipped ({exc})", file=sys.stderr)
|
||||
COVERAGE_CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
||||
scratch = cache.with_suffix(f".{os.getpid()}.tmp")
|
||||
with scratch.open("wb") as handle:
|
||||
pickle.dump({"platforms": names, "coverages": coverages}, handle,
|
||||
protocol=pickle.HIGHEST_PROTOCOL)
|
||||
scratch.replace(cache)
|
||||
# generate_site and generate_readme both purge here. One unlinking
|
||||
# what the other had just listed ended it on FileNotFoundError.
|
||||
for stale in COVERAGE_CACHE_DIR.glob("*.pickle"):
|
||||
if stale != cache:
|
||||
stale.unlink(missing_ok=True)
|
||||
ordered = {name: coverages[name] for name in platform_names if name in coverages}
|
||||
if report:
|
||||
for name in names:
|
||||
if name in ordered:
|
||||
report(name, ordered[name])
|
||||
return ordered
|
||||
|
||||
|
||||
def release_totals(platform_name: str, record: dict) -> tuple[int | None, int | None]:
|
||||
"""Files and bytes of the pack the latest release serves for a platform.
|
||||
|
||||
The Download link gives that release, so these are the figures a reader
|
||||
can check against an extraction. The install manifests describe what
|
||||
main would build today, which is a different pack as soon as a commit
|
||||
lands after the release. Returns (None, None) for a platform the release
|
||||
carries no pack for.
|
||||
"""
|
||||
pack = releaserecord.pack_for(platform_name, record)
|
||||
if not pack:
|
||||
return None, None
|
||||
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"
|
||||
|
||||
|
||||
def asset_links(
|
||||
platform_name: str, record: dict, repo: str, label: str, attrs: str = "",
|
||||
button: Callable[[str, str], str] | None = None,
|
||||
) -> str:
|
||||
"""Markdown links to the files of a platform's pack in the recorded release.
|
||||
|
||||
Written on the platform's get/ page only: every other surface links that
|
||||
page, whose address does not change with the release. A pack published
|
||||
whole gets one link labelled *label*. A pack in parts gets one link per
|
||||
part, since every part is needed, after the number of files to download:
|
||||
a reader who took one link for the pack extracted half of it. *repo* is
|
||||
the repository URL, *attrs* an attribute list put after each link, or
|
||||
*button* the function that draws each link as a button. Without a
|
||||
recorded release the link is the latest release page.
|
||||
"""
|
||||
pack = releaserecord.pack_for(platform_name, record)
|
||||
tag = record.get("tag")
|
||||
assets = pack.get("assets") if pack else None
|
||||
def link(text: str, url: str) -> str:
|
||||
return button(text, url) if button else f"[{text}]({url}){attrs}"
|
||||
|
||||
if not tag or not assets:
|
||||
return link(label, f"{repo}/releases/latest")
|
||||
urls = [f"{repo}/releases/download/{tag}/{asset}" for asset in assets]
|
||||
if len(urls) == 1:
|
||||
return link(label, urls[0])
|
||||
styled = bool(attrs or button)
|
||||
parts = [
|
||||
link(f"{'P' if styled else 'p'}art {number} of {len(urls)}", url)
|
||||
for number, url in enumerate(urls, 1)
|
||||
]
|
||||
if styled:
|
||||
return f"{len(urls)} files to download, all needed: " + " ".join(parts)
|
||||
return f"{label}, {len(urls)} files, all needed: " + ", ".join(parts)
|
||||
|
||||
|
||||
def download_links(
|
||||
platform_name: str, record: dict, label: str, attrs: str = "",
|
||||
button: Callable[[str, str], str] | None = None,
|
||||
site: str = "", page: str | None = None,
|
||||
) -> str:
|
||||
"""The download cell of a platform: its permanent get/ page.
|
||||
|
||||
*record* is the release record reduced to the release_pack platforms
|
||||
(release_record.advertised). A platform with a pack in it gets *label*
|
||||
linked to its page, which lists the files of the current release. A
|
||||
platform marked release_pack but missing from the release, added since,
|
||||
gets "No ZIP yet". Any other platform is served by the installer, and
|
||||
the cell says so instead of staying empty. *site* is the site root the
|
||||
get/ address hangs from, or *page* the address itself as the site links
|
||||
it, and *attrs* and *button* style the link.
|
||||
"""
|
||||
page = page or releaserecord.get_page(platform_name, site)
|
||||
def link(text: str) -> str:
|
||||
return button(text, page) if button else f"[{text}]({page}){attrs}"
|
||||
|
||||
state = release_state(platform_name, record)
|
||||
if state == "none":
|
||||
return link(NO_PACK)
|
||||
if state == "pending":
|
||||
return f"No ZIP yet: {link(NO_PACK.lower())}"
|
||||
return link(label)
|
||||
|
||||
|
||||
def extract_targets(platforms_dir: str) -> list[tuple[str, str]]:
|
||||
"""(display name, folder) per registered platform, where its pack extracts.
|
||||
|
||||
Read from the registry so the README, the site and the pack guide answer
|
||||
from one place. Sorted by display name.
|
||||
"""
|
||||
rows = [
|
||||
(platform_display(key, platforms_dir), entry["extract_to"])
|
||||
for key, entry in load_platform_registry(platforms_dir).items()
|
||||
if entry.get("extract_to")
|
||||
]
|
||||
return sorted(rows, key=lambda row: row[0].casefold())
|
||||
|
||||
|
||||
def own_root(config: dict) -> str:
|
||||
"""The folder a pack written from an empty base_destination starts with.
|
||||
|
||||
RetroDECK writes bios/ in front of its files, the MinUI family hands its
|
||||
cores folders below Bios/.
|
||||
"""
|
||||
root = declared_root(config)
|
||||
if root:
|
||||
return root
|
||||
tops = {directory.split("/", 1)[0] for directory in config.get("core_system_dirs") or {}}
|
||||
return tops.pop() if len(tops) == 1 else "bios"
|
||||
|
||||
|
||||
def extract_notes(platforms_dir: str, released_only: bool = False) -> list[str]:
|
||||
"""A pack whose entries carry their own root extracts above the BIOS folder.
|
||||
|
||||
*released_only* keeps the platforms a release publishes a pack for.
|
||||
"""
|
||||
folders = dict(extract_targets(platforms_dir))
|
||||
registry = load_platform_registry(platforms_dir)
|
||||
notes = []
|
||||
for key in sorted(registry):
|
||||
if released_only and registry[key].get("release_pack") is not True:
|
||||
continue
|
||||
config = load_platform_config(key, platforms_dir)
|
||||
display = display_name(config, key)
|
||||
if config.get("base_destination") == "" and display in folders:
|
||||
notes.append(
|
||||
f"The {display} pack holds its own `{own_root(config)}/` folder."
|
||||
f" Unzip it into `{folders[display]}`."
|
||||
)
|
||||
return notes
|
||||
from sitegen.coverage import platform_coverages
|
||||
from sitegen.extraction import extract_targets
|
||||
from sitegen.releasepacks import download_links, release_totals
|
||||
|
||||
|
||||
def _extract_cells(platforms_dir: str) -> dict[str, str]:
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
"""What the recorded release serves for each platform: pack totals, state and download links."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
|
||||
from model import releaserecord
|
||||
from sitegen.install import has_release_pack
|
||||
|
||||
|
||||
def release_totals(platform_name: str, record: dict) -> tuple[int | None, int | None]:
|
||||
"""Files and bytes of the pack the latest release serves for a platform.
|
||||
|
||||
The Download link gives that release, so these are the figures a reader
|
||||
can check against an extraction. The install manifests describe what
|
||||
main would build today, which is a different pack as soon as a commit
|
||||
lands after the release. Returns (None, None) for a platform the release
|
||||
carries no pack for.
|
||||
"""
|
||||
pack = releaserecord.pack_for(platform_name, record)
|
||||
if not pack:
|
||||
return None, None
|
||||
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"
|
||||
|
||||
|
||||
def asset_links(
|
||||
platform_name: str, record: dict, repo: str, label: str, attrs: str = "",
|
||||
button: Callable[[str, str], str] | None = None,
|
||||
) -> str:
|
||||
"""Markdown links to the files of a platform's pack in the recorded release.
|
||||
|
||||
Written on the platform's get/ page only: every other surface links that
|
||||
page, whose address does not change with the release. A pack published
|
||||
whole gets one link labelled *label*. A pack in parts gets one link per
|
||||
part, since every part is needed, after the number of files to download:
|
||||
a reader who took one link for the pack extracted half of it. *repo* is
|
||||
the repository URL, *attrs* an attribute list put after each link, or
|
||||
*button* the function that draws each link as a button. Without a
|
||||
recorded release the link is the latest release page.
|
||||
"""
|
||||
pack = releaserecord.pack_for(platform_name, record)
|
||||
tag = record.get("tag")
|
||||
assets = pack.get("assets") if pack else None
|
||||
def link(text: str, url: str) -> str:
|
||||
return button(text, url) if button else f"[{text}]({url}){attrs}"
|
||||
|
||||
if not tag or not assets:
|
||||
return link(label, f"{repo}/releases/latest")
|
||||
urls = [f"{repo}/releases/download/{tag}/{asset}" for asset in assets]
|
||||
if len(urls) == 1:
|
||||
return link(label, urls[0])
|
||||
styled = bool(attrs or button)
|
||||
parts = [
|
||||
link(f"{'P' if styled else 'p'}art {number} of {len(urls)}", url)
|
||||
for number, url in enumerate(urls, 1)
|
||||
]
|
||||
if styled:
|
||||
return f"{len(urls)} files to download, all needed: " + " ".join(parts)
|
||||
return f"{label}, {len(urls)} files, all needed: " + ", ".join(parts)
|
||||
|
||||
|
||||
def download_links(
|
||||
platform_name: str, record: dict, label: str, attrs: str = "",
|
||||
button: Callable[[str, str], str] | None = None,
|
||||
site: str = "", page: str | None = None,
|
||||
) -> str:
|
||||
"""The download cell of a platform: its permanent get/ page.
|
||||
|
||||
*record* is the release record reduced to the release_pack platforms
|
||||
(release_record.advertised). A platform with a pack in it gets *label*
|
||||
linked to its page, which lists the files of the current release. A
|
||||
platform marked release_pack but missing from the release, added since,
|
||||
gets "No ZIP yet". Any other platform is served by the installer, and
|
||||
the cell says so instead of staying empty. *site* is the site root the
|
||||
get/ address hangs from, or *page* the address itself as the site links
|
||||
it, and *attrs* and *button* style the link.
|
||||
"""
|
||||
page = page or releaserecord.get_page(platform_name, site)
|
||||
def link(text: str) -> str:
|
||||
return button(text, page) if button else f"[{text}]({page}){attrs}"
|
||||
|
||||
state = release_state(platform_name, record)
|
||||
if state == "none":
|
||||
return link(NO_PACK)
|
||||
if state == "pending":
|
||||
return f"No ZIP yet: {link(NO_PACK.lower())}"
|
||||
return link(label)
|
||||
@@ -26,7 +26,7 @@ from sitegen.guidepage import NO_ZIP_FAQ, devices_meta, first_screen_words, get_
|
||||
from sitegen.guides import fence, terminal_tabs, trust_box
|
||||
from sitegen.home import group_keys, next_block, runs_on_text, setup_picker
|
||||
from sitegen.install import installer_module, platform_display
|
||||
from sitegen.readme import NO_PACK, download_links, release_state
|
||||
from sitegen.releasepacks import NO_PACK, download_links, release_state
|
||||
|
||||
|
||||
# Build cross-reference indexes
|
||||
|
||||
Reference in new issue
Block a user