fix: record every profile a pass writes

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 16:43:46 +01:00
1 parent 2025a71cb9
commit 714683d63c
5 files changed
+91 -40

No files matched your search

+2 -2
View File
@@ -205,7 +205,7 @@ def main() -> None:
run_realign(args, selected)
return
reports, failed, complete = read_selected(args, selected, writes)
reports, failed, written, complete = read_selected(args, selected, writes)
# --changed-only narrows every output, not the text report alone: the
# documented `--all --changed-only --json` listed every profile.
@@ -214,7 +214,7 @@ def main() -> None:
if not args.changed_only or report.needs_review() or report.name in failed
]
complete = emit_reports(args, selected, reports, shown) is not False and complete
refresh_source_paths(args)
refresh_source_paths(args, written)
if not complete:
raise SystemExit(130)
if failed or (args.strict and any(
+8 -10
View File
@@ -8,32 +8,30 @@ from pathlib import Path
from core import upstream
from profiling.realign import realign_prose
from profiling.run import WRITTEN_PROFILES
from profiling.sourcepaths import refresh_source_paths
from profiling.sourcepaths import record_write, refresh_source_paths
from profiling.yamledit import YamlWriteError
def run_realign(args: argparse.Namespace, selected: dict) -> None:
"""--realign-prose over the selected profiles, exit 1 when one failed."""
failed: set[str] = set()
written: set[str] = set()
for name in selected:
profile_path = Path(args.emulators_dir) / f"{name}.yml"
if not profile_path.is_file():
continue
try:
before = profile_path.read_bytes()
for line in realign_prose(
profile_path, args.cache_dir, args.offline, args.dry_run
):
print(f"{name}: {line}")
if profile_path.read_bytes() != before:
WRITTEN_PROFILES.add(name)
with record_write(profile_path, name, written):
for line in realign_prose(
profile_path, args.cache_dir, args.offline, args.dry_run
):
print(f"{name}: {line}")
except upstream.UpstreamError as exc:
print(f"{name}: {exc}", file=sys.stderr)
failed.add(name)
except YamlWriteError as exc:
print(f"{name}: write refused: {exc}", file=sys.stderr)
failed.add(name)
refresh_source_paths(args)
refresh_source_paths(args, written)
if failed:
raise SystemExit(1)
+13 -12
View File
@@ -25,6 +25,7 @@ from profiling.reports import (
)
from profiling.repos import select_repo
from profiling.resolver import build_report
from profiling.sourcepaths import record_write
from profiling.triage import PROGRESS_SECONDS, Progress, print_interrupted, print_triage
from profiling.versions import (
newer_release,
@@ -135,7 +136,6 @@ def _promote(
file=sys.stderr,
)
return False
WRITTEN_PROFILES.add(name)
return True
@@ -311,8 +311,12 @@ def read_one_profile(
reports: list[ProfileReport],
failed: set[str],
writes: bool,
written: set[str],
) -> None:
"""Build one profile's report into ``reports``, then apply the writes."""
"""Build one profile's report into ``reports``, then apply the writes.
A profile the writes changed is added to ``written``.
"""
profile_path = Path(args.emulators_dir) / f"{name}.yml"
try:
report = _build_full_report(args, name, profile, profile_path, failed)
@@ -330,7 +334,8 @@ def read_one_profile(
reports.append(report)
if writes:
try:
_apply_writes(args, name, profile, report)
with record_write(profile_path, name, written):
_apply_writes(args, name, profile, report)
except YamlWriteError as exc:
# The guard already left the file untouched, so keep going.
print(f"{name}: write refused: {exc}", file=sys.stderr)
@@ -345,12 +350,13 @@ def read_one_profile(
def read_selected(
args: argparse.Namespace, selected: dict, writes: bool
) -> tuple[list[ProfileReport], set[str], bool]:
) -> tuple[list[ProfileReport], set[str], set[str], bool]:
"""Every selected profile's pass: the reports, the profiles that failed,
and whether the pass ran to its end."""
the profiles it wrote, and whether the pass ran to its end."""
# A profile that could not be compared or written is not a profile with
# nothing to review: it stays in every output and fails the run.
failed: set[str] = set()
written: set[str] = set()
reports: list[ProfileReport] = []
quiet = args.offline or len(selected) < 2
if not quiet:
@@ -364,18 +370,13 @@ def read_selected(
try:
for name, profile in selected.items():
progress.step(len(reports), name)
read_one_profile(args, name, profile, reports, failed, writes)
read_one_profile(args, name, profile, reports, failed, writes, written)
except KeyboardInterrupt:
# What was read is still worth printing: a ranking of 200 profiles
# beats none after 15 minutes.
print_interrupted(len(reports), len(selected), "the output covers those read")
complete = False
return reports, failed, complete
# Profiles this run wrote. Their new pins name trees the site's record of
# cited source paths does not hold yet.
WRITTEN_PROFILES: set[str] = set()
return reports, failed, written, complete
def _build_full_report(
+21 -3
View File
@@ -5,12 +5,30 @@ from __future__ import annotations
import argparse
import os
import sys
from collections.abc import Iterator
from contextlib import contextmanager
from pathlib import Path
from model.profiles import load_emulator_profiles
from profiling.run import WRITTEN_PROFILES
def refresh_source_paths(args: argparse.Namespace) -> None:
@contextmanager
def record_write(path: Path, name: str, written: set[str]) -> Iterator[None]:
"""Add *name* to *written* when the profile's bytes changed in the block.
Every writer of a pass runs inside it, so a new writer cannot forget to
say it wrote: --backfill-commits and --attribute-refs never did, and the
pins they wrote stayed out of the record. A write put back is no write.
"""
before = path.read_bytes() if path.is_file() else None
try:
yield
finally:
if path.is_file() and path.read_bytes() != before:
written.add(name)
def refresh_source_paths(args: argparse.Namespace, written: set[str]) -> None:
"""Rebuild the site's record of cited source paths after a write.
Each bump left website/src/data/source-paths.json behind its pins, and
@@ -18,7 +36,7 @@ def refresh_source_paths(args: argparse.Namespace) -> None:
--fetch by hand. A run that writes nothing, or makes no request, leaves
it alone.
"""
if not WRITTEN_PROFILES or args.dry_run or args.offline or os.environ.get("RETROBIOS_OFFLINE"):
if not written or args.dry_run or args.offline or os.environ.get("RETROBIOS_OFFLINE"):
return
from core.artifacts import ArtifactLockBusy
from model.profiles import emulator_profiles_cache