fix: accept core names in profile_sync and audit

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 05:59:51 +01:00
1 parent 0107ac8062
commit fc70a1afa6
4 files changed
+70 -47

No files matched your search

+11 -9
View File
@@ -25,10 +25,11 @@ from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from core import upstream
from core.cli import add_repo_inputs, require_directory, suggest_names
from core.cli import add_repo_inputs, require_directory
from profiling.citations import collect_citations
from profiling.repos import select_views
from model.sourceref import ref_role, split_source_ref
from model.profiles import ProfileSelectionError, load_emulator_profiles, resolve_profile_name
from model.safeparse import yaml_load
# Ways a program asks for somewhere to read from.
@@ -123,15 +124,16 @@ def main() -> None:
parser.error("name profiles or pass --all, not both")
require_directory(args.emulators_dir, "--emulators-dir")
known = sorted(path.stem for path in Path(args.emulators_dir).glob("*.yml"))
unknown = [name for name in args.emulators if name not in known]
if unknown:
raise SystemExit(
"ERROR: unknown profile " + ", ".join(unknown) + ". "
+ suggest_names(unknown, known, "python scripts/verify.py --list-emulators")
)
names = args.emulators
profiles = load_emulator_profiles(args.emulators_dir, skip_aliases=False) if args.emulators else {}
try:
names = [
resolve_profile_name(name, profiles, "python scripts/verify.py --list-emulators")
for name in args.emulators
]
except ProfileSelectionError as exc:
raise SystemExit(f"ERROR: {exc}") from None
if args.all:
known = sorted(path.stem for path in Path(args.emulators_dir).glob("*.yml"))
names = []
for name in known:
with open(Path(args.emulators_dir) / f"{name}.yml", encoding="utf-8") as handle:
+30 -24
View File
@@ -109,6 +109,35 @@ def entry_serves_systems(entry: dict, profile: dict, system_ids: list[str]) -> b
return bool(wanted & {norm_system_id(sid) for sid in entry_system_ids(entry, profile)})
def resolve_profile_name(
name: str, all_profiles: dict, hint_command: str = "--list-emulators"
) -> str:
"""The profile a name selects: its own key, else the one profile whose
cores: names it.
A buildbot name (pcfx, advmame) lives in a profile's cores:, and the
spelling hints sent pcfx to two PlayStation cores. The hints are drawn
from what --list-emulators shows.
"""
if name in all_profiles:
return name
claimants = sorted(
key for key in upstream_profile_index(all_profiles).get(name, ())
if all_profiles[key].get("type") != "launcher" and all_profiles[key].get("role") != "test"
)
if len(claimants) == 1:
return claimants[0]
if claimants:
raise ProfileSelectionError(
f"{name} is a core name of {', '.join(claimants)}: "
f"use --emulator with one of them"
)
available = sorted(key for key, value in all_profiles.items() if is_emulator(value))
raise ProfileSelectionError(
f"emulator '{name}' not found\n" + suggest_names([name], available, hint_command)
)
def select_emulator_profiles(
requested: list[str],
all_profiles: dict,
@@ -124,30 +153,7 @@ def select_emulator_profiles(
"""
selected: list[tuple[str, dict]] = []
for name in requested:
if name not in all_profiles:
# A buildbot name (pcfx, advmame) lives in a profile's cores:,
# and the spelling hints sent pcfx to two PlayStation cores.
claimants = sorted(
key for key in upstream_profile_index(all_profiles).get(name, ())
if all_profiles[key].get("type") != "launcher" and all_profiles[key].get("role") != "test"
)
if len(claimants) == 1:
name = claimants[0]
elif claimants:
raise ProfileSelectionError(
f"{name} is a core name of {', '.join(claimants)}: "
f"use --emulator with one of them"
)
if name not in all_profiles:
available = sorted(
key
for key, value in all_profiles.items()
if is_emulator(value)
)
raise ProfileSelectionError(
f"emulator '{name}' not found\n"
+ suggest_names([name], available, "--list-emulators")
)
name = resolve_profile_name(name, all_profiles)
profile = all_profiles[name]
kind = profile.get("type", "libretro")
if kind == "alias":
+9 -14
View File
@@ -24,7 +24,7 @@ from core import upstream
from profiling import version_basis
from model.systems import norm_system_id, system_index
from core.github import github_token
from model.profiles import is_emulator, load_emulator_profiles
from model.profiles import ProfileSelectionError, is_emulator, load_emulator_profiles, resolve_profile_name
from core.cli import add_repo_inputs, suggest_names
from profiling.bump import DEFAULT_CACHE, write_version
from profiling.realign import realign_prose
@@ -308,19 +308,14 @@ def select_profiles(profiles: dict, args: argparse.Namespace) -> dict:
print(f"the branch {verb} no profile against {base}", file=sys.stderr)
return selected
if args.emulator:
names = [args.emulator] if isinstance(args.emulator, str) else args.emulator
unknown = [name for name in names if name not in profiles]
if unknown:
# Suggested from what the listing it names shows: counted over the
# alias and test profiles too, "lists all 553" pointed at 530 lines.
listed = sorted(
name for name, profile in profiles.items()
if is_emulator(profile)
)
raise SystemExit(
f"ERROR: unknown profile {', '.join(unknown)}. "
+ suggest_names(unknown, listed, "python scripts/verify.py --list-emulators")
)
requested = [args.emulator] if isinstance(args.emulator, str) else args.emulator
try:
names = [
resolve_profile_name(name, profiles, "python scripts/verify.py --list-emulators")
for name in requested
]
except ProfileSelectionError as exc:
raise SystemExit(f"ERROR: {exc}") from None
return {name: profiles[name] for name in dict.fromkeys(names)}
# --system matches as verify.py --list-systems lists and --system selects:
+20
View File
@@ -57,6 +57,26 @@ class ABuildbotNameSelectsItsProfile(unittest.TestCase):
select_emulator_profiles(["pcsx3"], self.PROFILES)
self.assertIn("Close match", str(caught.exception))
def test_profile_sync_and_fileless_audit_take_the_core_name(self):
"""Both refused pcfx, which verify --emulator accepts."""
import argparse
import profile_sync
args = argparse.Namespace(changed=False, added=False, emulator=["pcfx"])
self.assertEqual(list(profile_sync.select_profiles(self.PROFILES, args)), ["beetle_pcfx"])
proc = subprocess.run(
[sys.executable, "scripts/fileless_audit.py", "pcfxx", "--offline"],
cwd=REPO_ROOT, capture_output=True, text=True, timeout=600, check=False,
)
self.assertNotEqual(proc.returncode, 0)
listed = subprocess.run(
[sys.executable, "scripts/verify.py", "--list-emulators"],
cwd=REPO_ROOT, capture_output=True, text=True, timeout=600, check=False,
).stdout
count = len([line for line in listed.splitlines() if line.strip()])
self.assertIn(f"lists all {count}.", proc.stderr)
def test_cross_reference_reports_the_resolved_profile(self):
"""cross_reference filtered on the typed name, found no profile under
it and answered `pcfx is not run by None`."""