mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: let verify_emulator raise a bad name
verify_emulator and verify_system raised SystemExit from a library: the verify command now prints and exits, and the pipeline's emulator pack comparison no longer selects the profiles a second time to avoid it.
This commit is contained in:
1 parent
5c3f2c7146
commit
ad37a73964
4 files changed
+61
-50
No files matched your search
@@ -57,7 +57,6 @@ def check_emulator_packs(
|
||||
ProfileSelectionError,
|
||||
load_emulator_profiles,
|
||||
profiles_for_systems,
|
||||
select_emulator_profiles,
|
||||
)
|
||||
from model.systems import norm_system_id
|
||||
from core.ziptools import build_zip_contents_index
|
||||
@@ -68,21 +67,25 @@ def check_emulator_packs(
|
||||
zip_contents = build_zip_contents_index(db)
|
||||
profiles = load_emulator_profiles(emulators_dir, skip_aliases=False)
|
||||
|
||||
def compare(names: list[str], standalone: bool, label: str, **narrowing: object) -> bool:
|
||||
def compare(names: list[str], standalone: bool, label: str, **narrowing: object) -> bool | None:
|
||||
"""Whether the two sides agree, None when the profiles have no such build."""
|
||||
record = archive.PackRecord()
|
||||
# The pack is built offline: verify counts a release asset the cache
|
||||
# lacks the same way, missing, as the narrowed-pack step does.
|
||||
with packresolve.offline(), contextlib.redirect_stdout(io.StringIO()), \
|
||||
contextlib.redirect_stderr(io.StringIO()):
|
||||
try:
|
||||
report = emulatorcheck.verify_emulator(
|
||||
names, emulators_dir, db, standalone, platforms_dir=platforms_dir,
|
||||
**narrowing,
|
||||
)
|
||||
except ProfileSelectionError:
|
||||
return None
|
||||
emulatorpack.build_emulator_pack(
|
||||
names, emulators_dir, db, "bios", "", standalone,
|
||||
zip_contents=zip_contents, offline=True, platforms_dir=platforms_dir,
|
||||
record=record, **narrowing,
|
||||
)
|
||||
report = emulatorcheck.verify_emulator(
|
||||
names, emulators_dir, db, standalone, platforms_dir=platforms_dir,
|
||||
**narrowing,
|
||||
)
|
||||
lines = set_difference_lines(
|
||||
label, set(report["pack_destinations"]), set(record.files)
|
||||
)
|
||||
@@ -96,14 +99,13 @@ def check_emulator_packs(
|
||||
if profiles[name].get("type") == "alias":
|
||||
continue # selects the profile it names, compared under that name
|
||||
for standalone in (False, True):
|
||||
try:
|
||||
select_emulator_profiles([name], profiles, standalone)
|
||||
except ProfileSelectionError:
|
||||
continue
|
||||
for tag, narrowing in emulator_variants([profiles[name]], full):
|
||||
compared += 1
|
||||
label = f"{name}{' --standalone' if standalone else ''}{tag}"
|
||||
all_ok = compare([name], standalone, label, **narrowing) and all_ok
|
||||
equal = compare([name], standalone, label, **narrowing)
|
||||
if equal is None:
|
||||
break # the selection does not depend on the narrowing
|
||||
compared += 1
|
||||
all_ok = equal and all_ok
|
||||
print(f" {compared} emulator packs compared, {'all equal' if all_ok else 'differences above'}")
|
||||
# A system pack builds every profile of the system together: a placement
|
||||
# rule that only goes wrong when two profiles share a path (the bluemsx
|
||||
@@ -124,11 +126,12 @@ def check_emulator_packs(
|
||||
for tag, narrowing in emulator_variants(
|
||||
[profiles[n] for n in matching if n in profiles], full
|
||||
):
|
||||
compared += 1
|
||||
label = f"--system {sid}{' --standalone' if standalone else ''}{tag}"
|
||||
systems_ok = compare(
|
||||
matching, standalone, label, system_ids=[sid], **narrowing
|
||||
) and systems_ok
|
||||
equal = compare(matching, standalone, label, system_ids=[sid], **narrowing)
|
||||
if equal is None:
|
||||
break
|
||||
compared += 1
|
||||
systems_ok = equal and systems_ok
|
||||
print(f" {compared} system packs compared, "
|
||||
f"{'all equal' if systems_ok else 'differences above'}")
|
||||
return all_ok and systems_ok
|
||||
@@ -3,7 +3,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
@@ -13,7 +12,6 @@ from core.ziptools import build_zip_contents_index
|
||||
from model.alternatives import set_requirements, settle_sets, slot_set_keys
|
||||
from model.database import sha1_at
|
||||
from model.profiles import (
|
||||
ProfileSelectionError,
|
||||
load_emulator_profiles,
|
||||
no_profile_for_systems,
|
||||
profiles_for_systems,
|
||||
@@ -45,6 +43,10 @@ from resolve.validation import (
|
||||
_REPO_PLATFORMS = str(REPO_ROOT / "platforms")
|
||||
|
||||
|
||||
class NoSystemProfileError(ValueError):
|
||||
"""No profile serves the systems asked for."""
|
||||
|
||||
|
||||
# Emulator/system mode verification
|
||||
|
||||
|
||||
@@ -70,19 +72,6 @@ def _effective_validation_label(details: list[dict], validation_index: dict) ->
|
||||
return "+".join(sorted(all_checks))
|
||||
|
||||
|
||||
def _select_profiles(
|
||||
profile_names: list[str],
|
||||
all_profiles: dict,
|
||||
standalone: bool,
|
||||
) -> list[tuple[str, dict]]:
|
||||
"""Resolve the named profiles, stopping the run on a bad name."""
|
||||
try:
|
||||
return select_emulator_profiles(profile_names, all_profiles, standalone)
|
||||
except ProfileSelectionError as exc:
|
||||
print(f"Error: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
_HASH_CONTRADICTED = "declared hash contradicted by the local file"
|
||||
|
||||
# Reduced in the order generate_emulator_pack chooses, so the
|
||||
@@ -541,11 +530,12 @@ def verify_emulator(
|
||||
`required_only` reports on the pack built with --required-only: a loose
|
||||
file or tree marked ``required: false`` is left out, and an archive when
|
||||
it and every member it carries are optional, as the builder leaves them.
|
||||
A name no profile answers for raises ProfileSelectionError.
|
||||
"""
|
||||
# Also load aliases for redirect messages
|
||||
all_profiles = load_emulator_profiles(emulators_dir, skip_aliases=False)
|
||||
|
||||
selected = _select_profiles(profile_names, all_profiles, standalone)
|
||||
selected = select_emulator_profiles(profile_names, all_profiles, standalone)
|
||||
# The member index only answers a zipped_file entry, and decompressing
|
||||
# every archive took 23 of the 24 seconds of a run that had none.
|
||||
zip_contents = (
|
||||
@@ -630,13 +620,16 @@ def verify_system(
|
||||
platforms_dir: str = _REPO_PLATFORMS,
|
||||
required_only: bool = False,
|
||||
) -> dict:
|
||||
"""Verify files for all emulators supporting given system IDs."""
|
||||
"""Verify files for all emulators supporting given system IDs.
|
||||
|
||||
Raises NoSystemProfileError when no profile serves them, and
|
||||
ProfileSelectionError as verify_emulator does.
|
||||
"""
|
||||
profiles = load_emulator_profiles(emulators_dir)
|
||||
matching = profiles_for_systems(profiles, system_ids, standalone)
|
||||
|
||||
if not matching:
|
||||
print(no_profile_for_systems(profiles, system_ids, standalone), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
raise NoSystemProfileError(no_profile_for_systems(profiles, system_ids, standalone))
|
||||
|
||||
return verify_emulator(
|
||||
matching, emulators_dir, db, standalone, regions=regions,
|
||||
|
||||
+26
-11
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import sys
|
||||
|
||||
from model.cliargs import (
|
||||
comma_list,
|
||||
@@ -15,8 +16,9 @@ from model.cliargs import (
|
||||
work_from_repo_root,
|
||||
)
|
||||
from model.database import load_database
|
||||
from model.profiles import ProfileSelectionError
|
||||
from model.registry import load_data_dir_registry
|
||||
from packs.emulatorcheck import verify_emulator, verify_system
|
||||
from packs.emulatorcheck import NoSystemProfileError, verify_emulator, verify_system
|
||||
from packs.strictgate import exit_if_strict
|
||||
from packs.verifyoptions import check_mode, refuse_listing_narrowings
|
||||
from packs.verifyplatforms import PlatformRun, verify_platforms
|
||||
@@ -24,19 +26,32 @@ from packs.verifyprint import print_emulator_run, print_platform_results
|
||||
|
||||
|
||||
def _run_emulator_mode(args: argparse.Namespace, db: dict, regions: list[str]) -> None:
|
||||
print_emulator_run(args, verify_emulator(
|
||||
comma_list(args.emulator), args.emulators_dir, db, args.standalone,
|
||||
regions=regions, platforms_dir=args.platforms_dir,
|
||||
required_only=args.required_only,
|
||||
))
|
||||
try:
|
||||
report = verify_emulator(
|
||||
comma_list(args.emulator), args.emulators_dir, db, args.standalone,
|
||||
regions=regions, platforms_dir=args.platforms_dir,
|
||||
required_only=args.required_only,
|
||||
)
|
||||
except ProfileSelectionError as exc:
|
||||
print(f"Error: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print_emulator_run(args, report)
|
||||
|
||||
|
||||
def _run_system_mode(args: argparse.Namespace, db: dict, regions: list[str]) -> None:
|
||||
print_emulator_run(args, verify_system(
|
||||
comma_list(args.system), args.emulators_dir, db, args.standalone,
|
||||
regions=regions, platforms_dir=args.platforms_dir,
|
||||
required_only=args.required_only,
|
||||
))
|
||||
try:
|
||||
report = verify_system(
|
||||
comma_list(args.system), args.emulators_dir, db, args.standalone,
|
||||
regions=regions, platforms_dir=args.platforms_dir,
|
||||
required_only=args.required_only,
|
||||
)
|
||||
except NoSystemProfileError as exc:
|
||||
print(exc, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except ProfileSelectionError as exc:
|
||||
print(f"Error: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
print_emulator_run(args, report)
|
||||
|
||||
|
||||
def _run_platform_mode(
|
||||
|
||||
+4
-4
@@ -38,7 +38,7 @@ from core.ziptools import build_zip_contents_index, check_inside_zip, safe_extra
|
||||
from core.hashing import compute_hashes, md5_composite, parse_hash_list
|
||||
from model.declarations import expand_platform_declared_names
|
||||
from resolve.grouping import group_identical_platforms
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.profiles import ProfileSelectionError, load_emulator_profiles
|
||||
from model.platforms import load_platform_config
|
||||
from resolve.localfile import resolve_local_file
|
||||
from resolve.cores import resolve_platform_cores
|
||||
@@ -1498,7 +1498,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_92_verify_emulator_libretro_only_rejects_standalone(self):
|
||||
"""Libretro-only profile rejects --standalone."""
|
||||
with self.assertRaises(SystemExit):
|
||||
with self.assertRaises(ProfileSelectionError):
|
||||
verify_emulator(["test_hle"], self.emulators_dir, self.db, standalone=True)
|
||||
|
||||
def test_92b_verify_emulator_game_type_rejects_standalone(self):
|
||||
@@ -1511,7 +1511,7 @@ class TestE2E(unittest.TestCase):
|
||||
}
|
||||
with open(os.path.join(self.emulators_dir, "test_game.yml"), "w") as fh:
|
||||
yaml.dump(game, fh)
|
||||
with self.assertRaises(SystemExit):
|
||||
with self.assertRaises(ProfileSelectionError):
|
||||
verify_emulator(["test_game"], self.emulators_dir, self.db, standalone=True)
|
||||
|
||||
def test_93_verify_emulator_alias_selects_its_profile(self):
|
||||
@@ -1524,7 +1524,7 @@ class TestE2E(unittest.TestCase):
|
||||
|
||||
def test_94_verify_emulator_launcher_rejected(self):
|
||||
"""Launcher profile produces error."""
|
||||
with self.assertRaises(SystemExit):
|
||||
with self.assertRaises(ProfileSelectionError):
|
||||
verify_emulator(["test_launcher"], self.emulators_dir, self.db)
|
||||
|
||||
def test_95_verify_emulator_validation_applied(self):
|
||||
|
||||
Reference in new issue
Block a user