fix: count gap sources once for page and text

This commit is contained in:
Abdessamad Derraz committed 2026-11-22 00:58:05 +01:00
1 parent 5dbd2df9ec
commit 5e7593b3bf
5 files changed
+37 -30

No files matched your search

+18
View File
@@ -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.
+4 -10
View File
@@ -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"
-17
View File
@@ -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", "")
+3 -3
View File
@@ -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'<span class="rb-badge rb-badge-danger">{to_source}</span>'
+12
View File
@@ -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."""