refactor: step 5 reads counts both tools record

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:50:42 +01:00
1 parent cf7e13808f
commit 9814bb1234
21 files changed
+428 -432

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
"""The counts each full platform pack hands the pipeline's consistency check."""
from __future__ import annotations
import json
from dataclasses import asdict, dataclass
from pathlib import Path
@dataclass(frozen=True)
class PackCounts:
"""What a built pack holds, by the builder's own count.
``ok`` and ``total`` are the platform's declared files judged in the
pack's verification mode, ``core_files`` what the pack takes from the
cores' profiles, and ``unsafe_excluded`` the files left out because the
frontend would reject their hash.
"""
archive: str
ok: int
total: int
core_files: int
unsafe_excluded: int
def pack_counts(archive: str, file_status: dict[str, str], core_files: int) -> PackCounts:
"""A pack's counts from the verdict of each declared file."""
statuses = list(file_status.values())
return PackCounts(
archive=archive,
ok=statuses.count("ok"),
total=len(statuses),
core_files=core_files,
unsafe_excluded=statuses.count("excluded"),
)
def write_pack_counts(path: str, packs: list[tuple[str, list[str], PackCounts]]) -> None:
"""Each pack's printed label, registry ids and counts, as a JSON list."""
Path(path).write_text(json.dumps(
[{"label": label, "platforms": platforms, **asdict(counts)}
for label, platforms, counts in packs],
indent=1, sort_keys=True,
))
def read_pack_counts(path: str) -> list[dict]:
"""The packs a build recorded with write_pack_counts."""
packs = json.loads(Path(path).read_text())
if not isinstance(packs, list):
raise ValueError(f"{path} is not a list of packs")
return packs
+16
View File
@@ -81,6 +81,21 @@ def _argument_conflicts(args: argparse.Namespace) -> list[tuple[bool, str]]:
(one_per_slot and args.manifest, "--one-per-slot is incompatible with --manifest"),
(one_per_slot and has_emulator, "--one-per-slot is incompatible with --emulator"),
(one_per_slot and has_system, "--one-per-slot is incompatible with --system"),
*_counts_conflicts(args, has_platform or has_all, has_system or has_from_md5),
]
def _counts_conflicts(
args: argparse.Namespace, platform_run: bool, narrowed: bool,
) -> list[tuple[bool, str]]:
"""--counts describes the full platform packs: another mode refuses it."""
counts = bool(getattr(args, "counts", None))
return [
(counts and not platform_run, "--counts requires --platform or --all"),
(counts and args.manifest, "--counts is incompatible with --manifest"),
(counts and args.split, "--counts is incompatible with --split"),
(counts and narrowed,
"--counts describes the full pack and is incompatible with --system and --from-md5"),
]
@@ -204,6 +219,7 @@ def _given_flags(args: argparse.Namespace) -> set[str]:
"--list-emulators": args.list_emulators,
"--list-systems": args.list_systems,
"--list-targets": args.list_targets,
"--counts": getattr(args, "counts", None),
"--refresh-data": args.refresh_data,
"--no-refresh-data": args.no_refresh_data,
}
+10 -4
View File
@@ -51,6 +51,7 @@ from packs.extras import (
undeclared_report,
)
from packs.naming import file_name_part, pack_narrowings, platform_pack_name, platform_pack_stem
from packs.packcounts import PackCounts, pack_counts
from packs.paths import flat_arcname, save_layout
from packs.readme import build_agnostic_rename_readme, build_readme, save_place
from resolve import packfiles as packresolve, regions as resolve_regions, slot as slot_mod
@@ -101,11 +102,10 @@ def _report_pack_counts(
verification_mode: str,
tree_count: int = 0,
) -> None:
"""Print the line the pipeline's consistency check reads.
"""Print the pack's counts line.
The check compares these counts against what verify.py reports for
the same platform, so the wording is a contract: parse_pack_counts
in orchestrate/reports.py matches on it.
The pipeline's consistency check reads the same counts as data
(packs.packcounts), never this line.
"""
files_ok = sum(1 for s in file_status.values() if s == "ok")
files_untested = sum(1 for s in file_status.values() if s == "untested")
@@ -316,6 +316,7 @@ class PackOptions(PackNarrowing, _PartScope, total=False):
record: PackRecord | None
within: dict[str, str] | None
uncached_out: set[str] | None
counts: list[PackCounts] | None
@dataclass(frozen=True)
@@ -342,6 +343,7 @@ class _PackSettings:
record: PackRecord | None = None
within: dict[str, str] | None = None
uncached_out: set[str] | None = None
counts: list[PackCounts] | None = None
@dataclass
@@ -1093,6 +1095,8 @@ def generate_pack(
its group, and a name built from every system of a hundred-system group
is longer than a file name can be.
``counts``, when given, receives the pack's PackCounts once it is built.
``record`` builds the pack in memory (PackRecord): no archive is written,
no external file fetched, and the paths are kept on it.
@@ -1151,6 +1155,8 @@ def generate_pack(
build = _PlatformPackBuild(plan, zf, resolve, verdict, judge, resolve_extra)
build.run()
build.report()
if opts.counts is not None:
opts.counts.append(pack_counts(plan.zip_path, build.file_status, build.core_count))
return plan.zip_path
+18 -9
View File
@@ -24,6 +24,7 @@ from packs.manifest import generate_manifest
from packs.manifestrun import run_manifest_mode
from packs.naming import pack_narrowings, platform_pack_name, platform_target
from packs.outputdir import holds_other_kind, pack_output_lock
from packs.packcounts import PackCounts, write_pack_counts
from packs.packcheck import run_verify_packs
from packs.platformpack import generate_pack, generate_split_packs
from packs.runscope import settle_scope
@@ -60,19 +61,23 @@ def run_platform_packs(
# The packs this run writes, the only ones it verifies and rewrites.
built: set[str] = set()
# The full packs' counts, for --counts: the pipeline compares them with
# verify's.
recorded: list[tuple[str, list[str], PackCounts]] = []
record_counts = getattr(args, "counts", None)
failed: list[str] = []
for source, required_only in run_variants(args):
for group_platforms, representative in groups:
aliases = [p for p in group_platforms if p != representative]
if aliases:
all_names = [
load_platform_config(p, args.platforms_dir).get("platform", p)
for p in group_platforms
]
label = " / ".join(all_names)
print(f"\nGenerating pack for {label} {pack_label(source, required_only)}...")
else:
print(f"\nGenerating pack for {representative} {pack_label(source, required_only)}...")
label = " / ".join(
load_platform_config(p, args.platforms_dir).get("platform", p)
for p in group_platforms
) if aliases else representative
print(f"\nGenerating pack for {label} {pack_label(source, required_only)}...")
counts: list[PackCounts] | None = (
[] if record_counts and (source, required_only) == ("full", False) else None
)
zip_path = None
zip_paths: list = []
@@ -138,6 +143,7 @@ def run_platform_packs(
pack_name=group_name,
no_game_data=getattr(args, "no_game_data", False),
uncached_out=getattr(args, "uncached_trees", None),
counts=counts,
)
except (FileNotFoundError, OSError, yaml.YAMLError) as e:
print(f" ERROR: {e}", file=sys.stderr)
@@ -153,6 +159,7 @@ def run_platform_packs(
os.path.relpath(path, args.output_dir)
for path in ([zip_path] if zip_path else zip_paths)
)
recorded.extend((label, group_platforms, c) for c in counts or ())
if zip_path and not system_filter:
# The install list of the same choices names each file's
# systems: the pack records them, so a pack alone (a
@@ -170,6 +177,8 @@ def run_platform_packs(
uncached_out=getattr(args, "uncached_trees", None),
), target_list(board_list) if board_list.is_file() else None)
if record_counts:
write_pack_counts(record_counts, recorded)
all_ok = finalize_platform_packs(args, db, data_registry, built, systems_for, system_filter)
if failed:
# Verification only sees the ZIPs that exist, so a pack that was never
+18 -12
View File
@@ -243,6 +243,23 @@ def split_undeclared(undeclared: list[dict]) -> tuple[list[dict], list[dict], li
return game_data, placed, unplaced
def pack_shares(result: dict) -> tuple[int, int]:
"""The core files and the game data a platform's pack carries, by the report.
The builder's count, one file per pack path, when the platform pass
replayed it. Counting entries said 1130 for RetroArch, 48 more than the
pack holds: rom.key alone was claimed by three Amiga cores.
"""
packed = result.get("packed_extras")
if packed is not None:
return packed["bios"], packed["game_data"]
game_data, bios_files, _unplaced = split_undeclared(result.get("undeclared_files", []))
return (
sum(1 for u in bios_files if u["in_repo"]),
sum(1 for u in game_data if u["in_repo"] and u.get("in_pack", True)),
)
def core_required_missing(bios_files: list[dict]) -> list[dict]:
"""Core files a core cannot run without, absent from the collection.
@@ -303,15 +320,8 @@ def _print_undeclared_section(result: dict, verbose: bool) -> None:
for u in bios_files
if u["required"] and not u["in_repo"] and u.get("hle_fallback")
]
req_in_repo = [u for u in bios_files if u["required"] and u["in_repo"]]
opt_in_repo = [u for u in bios_files if not u["required"] and u["in_repo"]]
opt_not_in_repo = [u for u in bios_files if not u["required"] and not u["in_repo"]]
# The builder's count, one file per pack path, when the platform pass
# replayed it. Counting entries said 1130 for RetroArch, 48 more than the
# pack holds: rom.key alone was claimed by three Amiga cores.
core_in_pack = (
packed["bios"] if packed is not None else len(req_in_repo) + len(opt_in_repo)
)
core_in_pack, gd_packed = pack_shares(result)
core_missing_req = len(req_not_in_repo) + len(req_hle_not_in_repo)
core_missing_opt = len(opt_not_in_repo)
@@ -354,10 +364,6 @@ def _print_undeclared_section(result: dict, verbose: bool) -> None:
if game_data or (packed and packed.get("game_data")):
gd_missing = [u for u in game_data if not u["in_repo"]]
gd_packed = (
packed["game_data"] if packed is not None
else sum(1 for u in game_data if u["in_repo"] and u.get("in_pack", True))
)
gd_unplaced = [u for u in game_data if u["in_repo"] and not u.get("in_pack", True)]
if gd_missing or gd_packed or gd_unplaced:
listed = "" if verbose or not gd_missing else " (--verbose lists them)"
+1 -1
View File
@@ -22,7 +22,7 @@ def run_variants(args: argparse.Namespace) -> tuple[tuple[str, bool], ...]:
def pack_label(source: str, required_only: bool) -> str:
"""The variant tag orchestrate.reports.parse_pack_counts reads after a pack name."""
"""The variant tag printed after a pack name."""
return f"[source={source}, required]" if required_only else f"[source={source}]"
+17 -4
View File
@@ -5,7 +5,8 @@ from __future__ import annotations
import json
from pathlib import Path
from packs.verdicts import Status
from packs.report import pack_shares
from packs.verdicts import Severity, Status
def json_details(details: list[dict], verbose: bool) -> list[dict]:
@@ -25,11 +26,23 @@ def write_pack_destinations(
groups: list[tuple[list[str], str]],
group_results: list[tuple[dict, list[str]]],
) -> None:
"""The paths each pack holds according to the report, per platform, as JSON."""
"""What each platform's pack holds according to the report, as JSON.
Keyed by registry id: the name verify prints, its OK and total counts,
the core files and game data the pack takes from the cores, and the
paths it credits. The pipeline's consistency check reads them here
rather than from the printed report.
"""
destinations = {}
for (result, names), (group, _rep) in zip(group_results, groups):
core_files, game_data = pack_shares(result)
for name, key in zip(names, group):
destinations[name] = {
"platform": key, "pack_destinations": result["pack_destinations"],
destinations[key] = {
"platform": key,
"label": name,
"ok": result["severity_counts"][Severity.OK],
"total": result["total_files"],
"core_files": core_files + game_data,
"pack_destinations": result["pack_destinations"],
}
Path(path).write_text(json.dumps(destinations, indent=1, sort_keys=True))