From 5e7593b3bff9596145444d2b3351bc5eee12001d Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 22 Nov 2026 00:39:53 +0100 Subject: [PATCH] fix: count gap sources once for page and text --- scripts/packs/crossref.py | 18 ++++++++++++++++++ scripts/packs/crossreftext.py | 14 ++++---------- scripts/sitegen/crossref.py | 17 ----------------- scripts/sitegen/gaps.py | 6 +++--- tests/test_cross_reference_sources.py | 12 ++++++++++++ 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/scripts/packs/crossref.py b/scripts/packs/crossref.py index b90ad34dc..7f05250e7 100644 --- a/scripts/packs/crossref.py +++ b/scripts/packs/crossref.py @@ -716,6 +716,24 @@ SET_ASIDE = { } +GAP_SOURCES = ("bios", "data", "large_file", "missing", "bundled") + + +def gap_source_counts(data: dict) -> dict[str, int]: + """Where each undeclared file of one emulator comes from. + + A file installed with its emulator is neither one to source nor one the + pack brings, held or not (validation.deliverable leaves it out of every + pack): it counts as bundled whatever its source. + """ + counts = dict.fromkeys(GAP_SOURCES, 0) + for gap in data.get("gap_details") or []: + source = "bundled" if gap.get("bundled") else gap.get("source", "missing") + if source in counts: + counts[source] += 1 + return counts + + def profile_breakdown(data: dict) -> str: """Where each entry of a profile went, adding up to its file count. diff --git a/scripts/packs/crossreftext.py b/scripts/packs/crossreftext.py index e4af4bdb1..c4b5bff1e 100644 --- a/scripts/packs/crossreftext.py +++ b/scripts/packs/crossreftext.py @@ -3,7 +3,7 @@ from __future__ import annotations from core.text import count_text -from packs.crossref import profile_breakdown +from packs.crossref import gap_source_counts, profile_breakdown def print_launcher_unproven(rows: list[dict]) -> None: @@ -84,15 +84,9 @@ def print_report( if gaps == 0 and not show_clean: continue - # Counted once, for the heading and the total alike: a file installed - # with its emulator is neither one to source nor one the pack brings, - # held or not (validation.deliverable leaves it out of every pack). - bundled_gaps = [g for g in data["gap_details"] if g.get("bundled")] - emulator_bundled = len(bundled_gaps) - counts = {key: data.get(f"gap_{key}", 0) for key in totals} - for g in bundled_gaps: - counts[g.get("source", "missing")] -= 1 - counts["bundled"] = emulator_bundled + # Counted once, for the heading and the total alike. + counts = gap_source_counts(data) + emulator_bundled = counts["bundled"] parts = [f"{count} {key}" for key, count in counts.items() if count] status = ", ".join(parts) if parts else "OK" diff --git a/scripts/sitegen/crossref.py b/scripts/sitegen/crossref.py index a60c77706..5fcddf044 100644 --- a/scripts/sitegen/crossref.py +++ b/scripts/sitegen/crossref.py @@ -34,23 +34,6 @@ def _core_scope_note(config: dict, profiles: dict) -> str: return f" (all libretro, plus {count_text(others, 'other core')})" -def gap_sources(data: dict) -> dict[str, int]: - """Where each undeclared file of one emulator comes from. - - A file the emulator's own package installs is not one to find. The - report's gap_missing counts it, and the gaps page announced 1,356 files - to source where 609 are, with a red badge on emulators that have none. - """ - counts = {"bios": 0, "data": 0, "large_file": 0, "bundled": 0, "missing": 0} - for gap in data.get("gap_details") or []: - source = gap.get("source", "") - if source == "missing" and gap.get("bundled"): - source = "bundled" - if source in counts: - counts[source] += 1 - return counts - - def _xref_upstream(profile: dict) -> str: """The project a core comes from: its upstream, else its own source.""" raw = profile.get("upstream") or profile.get("source", "") diff --git a/scripts/sitegen/gaps.py b/scripts/sitegen/gaps.py index 2be4bcc0e..94464737a 100644 --- a/scripts/sitegen/gaps.py +++ b/scripts/sitegen/gaps.py @@ -13,12 +13,12 @@ from core.text import series from model.database import sha1_at from model.platforms import native_layer from model.profiles import is_emulator +from packs.crossref import gap_source_counts from resolve.cores import resolve_platform_cores from resolve.nativemode import check_label from sitegen import markup, wanted as sitewanted from sitegen.cards import PROVENANCE_LABELS, fetch_url from sitegen.config import date_line -from sitegen.crossref import gap_sources from sitegen.dataexports import build_emulator_gap_report from sitegen.emulatorsindex import content_check_ceiling from sitegen.parts import list_pages @@ -667,7 +667,7 @@ def _undeclared_gaps(report_all: dict) -> tuple[dict[str, int], int, list[tuple[ if data["gaps"] == 0: continue total_undeclared += data["gaps"] - for key, count in gap_sources(data).items(): + for key, count in gap_source_counts(data).items(): src_totals[key] += count emulator_gaps.append((emu_name, data)) return src_totals, total_undeclared, emulator_gaps @@ -678,7 +678,7 @@ def _complement_rows(emulator_gaps: list[tuple[str, dict]]) -> list[str]: rows = [] for emu_name, data in sorted(emulator_gaps, key=lambda x: -x[1]["gaps"]): display = data["emulator"] - sources = gap_sources(data) + sources = gap_source_counts(data) to_source = sources["missing"] missing_str = ( f'{to_source}' diff --git a/tests/test_cross_reference_sources.py b/tests/test_cross_reference_sources.py index d872ab6a6..8dd1c90af 100644 --- a/tests/test_cross_reference_sources.py +++ b/tests/test_cross_reference_sources.py @@ -154,6 +154,18 @@ class PlatformScopedEntries(unittest.TestCase): self.assertIn("0 available", text) self.assertIn("1 missing (need to be sourced)", text) + def test_the_page_and_the_text_count_sources_alike(self): + """The gaps page kept a held bundled file under bios where the text + report counted it bundled: 410 files in different columns.""" + from sitegen import gaps + + report = cross_reference(self.PROFILES, {}, self.DB, platform="plat") + totals, _total, _rows = gaps._undeclared_gaps(report) + self.assertEqual(totals["bundled"], 1) + self.assertEqual(totals["bios"], 0) + self.assertEqual(totals["missing"], 1) + self.assertNotIn("gap_sources", script_source("generate_site.py")) + def test_the_report_reads_the_shared_rules(self): """One rule, one function: a local `bool(f.get("bundled"))` answered differently from verify for every installed_on/not_bundled_on entry."""