mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: thin verify and cross_reference
Option checks, run modes and the strict exits move to packs (verifyoptions, verifyrun, verifyprint, strictgate, crossrefscope, crossrefreport). Both commands keep main and build_parser only.
This commit is contained in:
1 parent
37ec04aed1
commit
fd1c2e1c16
11 files changed
+351
-305
No files matched your search
+5
-105
@@ -15,27 +15,20 @@ Usage:
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from core.cli import add_repo_inputs
|
||||
from model.cliargs import platform_arg, list_emulator_profiles, require_platform
|
||||
from model.profiles import ProfileSelectionError, load_emulator_profiles, select_emulator_profiles
|
||||
from model.database import load_database
|
||||
from model.registry import load_data_dir_registry
|
||||
from model.cliargs import platform_arg
|
||||
from model.safeparse import require_yaml
|
||||
|
||||
from packs.crossreflaunchers import LAUNCHER_READS_KEY, LAUNCHER_UNPROVEN_KEY, launcher_rows
|
||||
from packs.crossrefrun import scope_gaps
|
||||
from packs.crossrefscope import TreeScope, tree_scope
|
||||
from packs.crossreftext import print_launcher_reads, print_launcher_unproven, print_report
|
||||
from packs.crossrefreport import run_gap_report
|
||||
|
||||
yaml = require_yaml()
|
||||
|
||||
|
||||
def _build_parser() -> argparse.ArgumentParser:
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False, description="Emulator vs platform gap analysis")
|
||||
add_repo_inputs(parser, "emulators", "platforms", "db")
|
||||
parser.add_argument("--emulator", "-e", help="Analyze single emulator")
|
||||
@@ -58,102 +51,9 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
return parser
|
||||
|
||||
|
||||
def _refuse_empty_scope(args: argparse.Namespace, emulator: str | None, tree: TreeScope) -> None:
|
||||
"""Why the scope holds no profile, said before ending the run."""
|
||||
platform_scope = tree.platform
|
||||
if (emulator and args.target and platform_scope is not None
|
||||
and emulator in platform_scope.run_anywhere):
|
||||
raise SystemExit(
|
||||
f"ERROR: {emulator} is not built for {args.platform}'s "
|
||||
f"{args.target} target; {args.platform} runs it elsewhere "
|
||||
f"(drop --target to see its files)"
|
||||
)
|
||||
if emulator and args.platform:
|
||||
raise SystemExit(f"ERROR: {emulator} is not run by {args.platform}")
|
||||
if emulator:
|
||||
raise SystemExit(
|
||||
f"ERROR: no platform with the {args.target} target builds {emulator} "
|
||||
f"for it (drop --target to see its files)"
|
||||
)
|
||||
if args.target and not args.platform:
|
||||
print(f"No platform runs a profiled emulator on {args.target}.", file=sys.stderr)
|
||||
else:
|
||||
print(f"{args.platform or 'The tree'} runs no profiled emulator.", file=sys.stderr)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = _build_parser()
|
||||
args = parser.parse_args()
|
||||
from model.cliargs import work_from_repo_root
|
||||
|
||||
work_from_repo_root(args, parser, ["emulators_dir", "platforms_dir", "db"])
|
||||
if args.list_emulators:
|
||||
ignored = [flag for flag, on in (
|
||||
("--emulator", args.emulator), ("--platform", args.platform),
|
||||
("--all", args.all), ("--target", args.target), ("--json", args.json),
|
||||
) if on]
|
||||
if ignored:
|
||||
parser.error(f"--list-emulators does not apply {', '.join(ignored)}")
|
||||
list_emulator_profiles(args.emulators_dir)
|
||||
return
|
||||
if args.platform and args.all:
|
||||
parser.error("--platform and --all are mutually exclusive")
|
||||
if args.platform:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
|
||||
import contextlib
|
||||
|
||||
from packs.datadirs import hold_data_dirs
|
||||
|
||||
# Files resolve against data/: the trees stay put until the process
|
||||
# ends, which releases the hold.
|
||||
held = contextlib.ExitStack()
|
||||
registry = load_data_dir_registry(args.platforms_dir)
|
||||
hold_data_dirs(held, registry)
|
||||
|
||||
profiles = load_emulator_profiles(args.emulators_dir)
|
||||
# Every profile's names and aliases, whatever --emulator or --platform keeps.
|
||||
all_profiles = profiles
|
||||
emulator = args.emulator
|
||||
if emulator:
|
||||
# A typo answered "No emulator profiles found" with exit 0.
|
||||
try:
|
||||
((emulator, _),) = select_emulator_profiles(
|
||||
[args.emulator],
|
||||
load_emulator_profiles(args.emulators_dir, skip_aliases=False),
|
||||
)
|
||||
except ProfileSelectionError as exc:
|
||||
raise SystemExit(f"ERROR: {exc}") from None
|
||||
profiles = {k: v for k, v in profiles.items() if k == emulator}
|
||||
|
||||
tree = tree_scope(args.platform, args.target, args.platforms_dir, profiles)
|
||||
if not tree.profiles:
|
||||
_refuse_empty_scope(args, emulator, tree)
|
||||
return
|
||||
|
||||
db = load_database(args.db)
|
||||
report = scope_gaps(tree, db, args.platforms_dir, args.platform)
|
||||
launcher_reads, unproven = launcher_rows(
|
||||
tree.selected, args.platforms_dir, db, all_profiles, registry, emulator,
|
||||
)
|
||||
|
||||
if args.json:
|
||||
print(json.dumps(
|
||||
{**report, LAUNCHER_READS_KEY: launcher_reads, LAUNCHER_UNPROVEN_KEY: unproven},
|
||||
indent=2,
|
||||
))
|
||||
return
|
||||
if emulator:
|
||||
scope = emulator
|
||||
elif args.platform:
|
||||
scope = f"the emulators {args.platform} runs"
|
||||
elif args.target:
|
||||
scope = f"the emulators built for {args.target}"
|
||||
else:
|
||||
scope = "all emulators"
|
||||
print_report(report, scope, show_clean=bool(args.emulator))
|
||||
print_launcher_reads(launcher_reads)
|
||||
print_launcher_unproven(unproven)
|
||||
parser = build_parser()
|
||||
run_gap_report(parser.parse_args(), parser)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"""A cross_reference run: its options checked, its scope chosen, its report printed."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import json
|
||||
|
||||
from model.cliargs import list_emulator_profiles, require_platform, work_from_repo_root
|
||||
from model.database import load_database
|
||||
from model.profiles import ProfileSelectionError, load_emulator_profiles, select_emulator_profiles
|
||||
from model.registry import load_data_dir_registry
|
||||
from packs.crossreflaunchers import LAUNCHER_READS_KEY, LAUNCHER_UNPROVEN_KEY, launcher_rows
|
||||
from packs.crossrefrun import scope_gaps
|
||||
from packs.crossrefscope import refuse_empty_scope, tree_scope
|
||||
from packs.crossreftext import print_launcher_reads, print_launcher_unproven, print_report
|
||||
from packs.datadirs import hold_data_dirs
|
||||
|
||||
|
||||
def _list_emulators(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
"""--list-emulators reads no other option: one given beside it is refused."""
|
||||
ignored = [flag for flag, on in (
|
||||
("--emulator", args.emulator), ("--platform", args.platform),
|
||||
("--all", args.all), ("--target", args.target), ("--json", args.json),
|
||||
) if on]
|
||||
if ignored:
|
||||
parser.error(f"--list-emulators does not apply {', '.join(ignored)}")
|
||||
list_emulator_profiles(args.emulators_dir)
|
||||
|
||||
|
||||
def _scope_label(args: argparse.Namespace, emulator: str | None) -> str:
|
||||
if emulator:
|
||||
return emulator
|
||||
if args.platform:
|
||||
return f"the emulators {args.platform} runs"
|
||||
if args.target:
|
||||
return f"the emulators built for {args.target}"
|
||||
return "all emulators"
|
||||
|
||||
|
||||
def run_gap_report(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
"""Check the options, then print the gap report of the scope they name."""
|
||||
work_from_repo_root(args, parser, ["emulators_dir", "platforms_dir", "db"])
|
||||
if args.list_emulators:
|
||||
_list_emulators(args, parser)
|
||||
return
|
||||
if args.platform and args.all:
|
||||
parser.error("--platform and --all are mutually exclusive")
|
||||
if args.platform:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
|
||||
# Files resolve against data/: the trees stay put until the process
|
||||
# ends, which releases the hold.
|
||||
held = contextlib.ExitStack()
|
||||
registry = load_data_dir_registry(args.platforms_dir)
|
||||
hold_data_dirs(held, registry)
|
||||
|
||||
profiles = load_emulator_profiles(args.emulators_dir)
|
||||
# Every profile's names and aliases, whatever --emulator or --platform keeps.
|
||||
all_profiles = profiles
|
||||
emulator = args.emulator
|
||||
if emulator:
|
||||
# A typo answered "No emulator profiles found" with exit 0.
|
||||
try:
|
||||
((emulator, _),) = select_emulator_profiles(
|
||||
[args.emulator],
|
||||
load_emulator_profiles(args.emulators_dir, skip_aliases=False),
|
||||
)
|
||||
except ProfileSelectionError as exc:
|
||||
raise SystemExit(f"ERROR: {exc}") from None
|
||||
profiles = {k: v for k, v in profiles.items() if k == emulator}
|
||||
|
||||
tree = tree_scope(args.platform, args.target, args.platforms_dir, profiles)
|
||||
if not tree.profiles:
|
||||
refuse_empty_scope(args, emulator, tree)
|
||||
return
|
||||
|
||||
db = load_database(args.db)
|
||||
report = scope_gaps(tree, db, args.platforms_dir, args.platform)
|
||||
launcher_reads, unproven = launcher_rows(
|
||||
tree.selected, args.platforms_dir, db, all_profiles, registry, emulator,
|
||||
)
|
||||
|
||||
if args.json:
|
||||
print(json.dumps(
|
||||
{**report, LAUNCHER_READS_KEY: launcher_reads, LAUNCHER_UNPROVEN_KEY: unproven},
|
||||
indent=2,
|
||||
))
|
||||
return
|
||||
print_report(report, _scope_label(args, emulator), show_clean=bool(args.emulator))
|
||||
print_launcher_reads(launcher_reads)
|
||||
print_launcher_unproven(unproven)
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
from model.platforms import load_platform_config
|
||||
@@ -98,3 +100,26 @@ def tree_scope(
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def refuse_empty_scope(args: argparse.Namespace, emulator: str | None, tree: TreeScope) -> None:
|
||||
"""Why the scope holds no profile, said before ending the run."""
|
||||
platform_scope = tree.platform
|
||||
if (emulator and args.target and platform_scope is not None
|
||||
and emulator in platform_scope.run_anywhere):
|
||||
raise SystemExit(
|
||||
f"ERROR: {emulator} is not built for {args.platform}'s "
|
||||
f"{args.target} target; {args.platform} runs it elsewhere "
|
||||
f"(drop --target to see its files)"
|
||||
)
|
||||
if emulator and args.platform:
|
||||
raise SystemExit(f"ERROR: {emulator} is not run by {args.platform}")
|
||||
if emulator:
|
||||
raise SystemExit(
|
||||
f"ERROR: no platform with the {args.target} target builds {emulator} "
|
||||
f"for it (drop --target to see its files)"
|
||||
)
|
||||
if args.target and not args.platform:
|
||||
print(f"No platform runs a profiled emulator on {args.target}.", file=sys.stderr)
|
||||
else:
|
||||
print(f"{args.platform or 'The tree'} runs no profiled emulator.", file=sys.stderr)
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
from packs.verdicts import Severity, Status
|
||||
|
||||
|
||||
@@ -33,3 +35,19 @@ def emulator_strict_failure(result: dict) -> str | None:
|
||||
if not missing:
|
||||
return None
|
||||
return f"ERROR: {len(missing)} required file(s) missing: {', '.join(missing)}"
|
||||
|
||||
|
||||
def exit_if_strict(strict: bool, results: list[dict]) -> None:
|
||||
"""Exit 1 under --strict when a platform result counts a critical file."""
|
||||
failure = platform_strict_failure(results)
|
||||
if strict and failure:
|
||||
print(failure, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def exit_if_strict_emulator(strict: bool, result: dict) -> None:
|
||||
"""Exit 1 under --strict when an emulator lacks a file it cannot run without."""
|
||||
failure = emulator_strict_failure(result)
|
||||
if strict and failure:
|
||||
print(failure, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
@@ -0,0 +1,57 @@
|
||||
"""The verify options a mode reads, and the ones it refuses beside it."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
|
||||
from model.cliargs import LISTING_FLAGS, mode_conflicts, refuse_beside_mode
|
||||
|
||||
|
||||
def refuse_listing_narrowings(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser
|
||||
) -> str | None:
|
||||
"""A listing reads --platform at most: anything else given beside it,
|
||||
another listing included, is refused (generate_pack applies the same
|
||||
table). The listing asked for, if any."""
|
||||
listings = [(flag, getattr(args, flag[2:].replace("-", "_"))) for flag in LISTING_FLAGS]
|
||||
given = {flag for flag, on in (
|
||||
*listings,
|
||||
("--platform", args.platform),
|
||||
("--all", args.all),
|
||||
("--emulator", args.emulator),
|
||||
("--system", args.system),
|
||||
("--region", getattr(args, "region", None)),
|
||||
("--target", getattr(args, "target", None)),
|
||||
("--standalone", args.standalone),
|
||||
("--json", args.json),
|
||||
("--strict", args.strict),
|
||||
("--verbose", args.verbose),
|
||||
("--destinations", args.destinations),
|
||||
("--offline", args.offline),
|
||||
("--no-game-data", getattr(args, "no_game_data", False)),
|
||||
("--required-only", args.required_only),
|
||||
) if on}
|
||||
return refuse_beside_mode(listings, given, LISTING_FLAGS, parser)
|
||||
|
||||
|
||||
def refuse_mode_flags(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
"""A flag the chosen mode does not read is refused, never ignored."""
|
||||
for refused, message in (
|
||||
*mode_conflicts(args),
|
||||
(args.destinations and args.system,
|
||||
"--destinations describes the full pack and is incompatible with --system"),
|
||||
(args.destinations and not (args.platform or args.all),
|
||||
"--destinations requires --platform or --all"),
|
||||
(args.destinations and getattr(args, "region", None),
|
||||
"--destinations describes the full pack and is incompatible with --region"),
|
||||
(args.destinations and args.required_only,
|
||||
"--destinations describes the full pack and is incompatible with --required-only"),
|
||||
):
|
||||
if refused:
|
||||
parser.error(message)
|
||||
|
||||
|
||||
def check_mode(args: argparse.Namespace, parser: argparse.ArgumentParser) -> bool:
|
||||
"""Refuse a request naming no mode or several, and say if it is the system mode."""
|
||||
refuse_mode_flags(args, parser)
|
||||
return bool(args.system) and not (args.platform or args.all)
|
||||
@@ -0,0 +1,40 @@
|
||||
"""A verify run's results printed, as text or JSON, then held to --strict."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
|
||||
from packs.report import print_emulator_result, print_platform_result
|
||||
from packs.strictgate import exit_if_strict_emulator
|
||||
from packs.verifyoutput import json_details, write_pack_destinations
|
||||
from packs.verifyplatforms import PlatformResults
|
||||
from packs.verifysummary import overall_summary
|
||||
|
||||
|
||||
def print_emulator_run(args: argparse.Namespace, result: dict) -> None:
|
||||
"""An --emulator or --system result, as text or JSON, then the strict gate."""
|
||||
if args.json:
|
||||
result["details"] = json_details(result["details"], args.verbose)
|
||||
print(json.dumps(result, indent=2))
|
||||
else:
|
||||
print_emulator_result(result, verbose=args.verbose)
|
||||
exit_if_strict_emulator(args.strict, result)
|
||||
|
||||
|
||||
def print_platform_results(args: argparse.Namespace, results: PlatformResults) -> None:
|
||||
group_results = results.group_results
|
||||
if not args.json:
|
||||
for result, group in group_results:
|
||||
print_platform_result(result, group, verbose=args.verbose)
|
||||
print()
|
||||
if len(group_results) > 1:
|
||||
print(overall_summary(group_results))
|
||||
|
||||
if args.destinations:
|
||||
write_pack_destinations(args.destinations, results.groups, group_results)
|
||||
|
||||
if args.json:
|
||||
for r in results.all_results.values():
|
||||
r["details"] = json_details(r["details"], args.verbose)
|
||||
print(json.dumps(results.all_results, indent=2))
|
||||
@@ -0,0 +1,95 @@
|
||||
"""A verify run: its options checked, then the emulator, system or platform mode."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
|
||||
from model.cliargs import (
|
||||
comma_list,
|
||||
requested_regions,
|
||||
require_platform,
|
||||
resolve_system_ids,
|
||||
run_listing,
|
||||
selected_platforms,
|
||||
work_from_repo_root,
|
||||
)
|
||||
from model.database import load_database
|
||||
from model.registry import load_data_dir_registry
|
||||
from packs.emulatorcheck import 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
|
||||
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,
|
||||
))
|
||||
|
||||
|
||||
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,
|
||||
))
|
||||
|
||||
|
||||
def _run_platform_mode(
|
||||
args: argparse.Namespace,
|
||||
parser: argparse.ArgumentParser,
|
||||
db: dict,
|
||||
regions: list[str],
|
||||
platform_systems: list[str] | None,
|
||||
) -> None:
|
||||
results = verify_platforms(selected_platforms(args, parser), db, PlatformRun(
|
||||
platforms_dir=args.platforms_dir,
|
||||
emulators_dir=args.emulators_dir,
|
||||
target=args.target,
|
||||
is_all=args.all,
|
||||
regions=regions,
|
||||
system_filter=platform_systems,
|
||||
no_game_data=getattr(args, "no_game_data", False),
|
||||
required_only=args.required_only,
|
||||
))
|
||||
print_platform_results(args, results)
|
||||
exit_if_strict(args.strict, [r for r, _ in results.group_results])
|
||||
|
||||
|
||||
def run_verify(
|
||||
held: contextlib.ExitStack, parser: argparse.ArgumentParser, args: argparse.Namespace
|
||||
) -> None:
|
||||
"""Check the options, hold the data trees in `held` and run the mode asked for."""
|
||||
work_from_repo_root(args, parser, ["db", "platforms_dir", "emulators_dir"])
|
||||
if args.platform:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
if args.offline:
|
||||
from resolve import packfiles as packresolve
|
||||
|
||||
packresolve.set_offline(True)
|
||||
|
||||
regions = requested_regions(args.region, parser)
|
||||
|
||||
if refuse_listing_narrowings(args, parser):
|
||||
run_listing(args, parser, args.list_platforms)
|
||||
return
|
||||
|
||||
system_mode = check_mode(args, parser)
|
||||
platform_systems = resolve_system_ids(args, parser)
|
||||
# The trees stay put while names resolve against them and files are read.
|
||||
from packs.datadirs import hold_data_dirs
|
||||
|
||||
hold_data_dirs(held, load_data_dir_registry(args.platforms_dir))
|
||||
|
||||
db = load_database(args.db)
|
||||
|
||||
if args.emulator:
|
||||
_run_emulator_mode(args, db, regions)
|
||||
elif system_mode:
|
||||
_run_system_mode(args, db, regions)
|
||||
else:
|
||||
_run_platform_mode(args, parser, db, regions, platform_systems)
|
||||
+5
-194
@@ -25,91 +25,27 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from core.cli import add_emulator_selection, add_repo_inputs
|
||||
from model.cliargs import (
|
||||
LISTING_FLAGS,
|
||||
comma_list,
|
||||
mode_conflicts,
|
||||
platform_arg,
|
||||
refuse_beside_mode,
|
||||
requested_regions,
|
||||
run_listing,
|
||||
work_from_repo_root,
|
||||
require_platform,
|
||||
resolve_system_ids,
|
||||
selected_platforms,
|
||||
)
|
||||
from model.registry import load_data_dir_registry
|
||||
from model.database import load_database
|
||||
from model.cliargs import platform_arg
|
||||
from model.safeparse import require_yaml
|
||||
|
||||
|
||||
from packs.emulatorcheck import verify_emulator, verify_system
|
||||
from packs.report import print_emulator_result, print_platform_result
|
||||
from packs.strictgate import emulator_strict_failure, platform_strict_failure
|
||||
from packs.verifyoutput import json_details, write_pack_destinations
|
||||
from packs.verifyplatforms import PlatformResults, PlatformRun, verify_platforms
|
||||
from packs.verifysummary import overall_summary
|
||||
from packs.verifyrun import run_verify
|
||||
|
||||
yaml = require_yaml()
|
||||
|
||||
|
||||
def _refuse_listing_narrowings(
|
||||
args: argparse.Namespace, parser: argparse.ArgumentParser
|
||||
) -> str | None:
|
||||
"""A listing reads --platform at most: anything else given beside it,
|
||||
another listing included, is refused (generate_pack applies the same
|
||||
table). The listing asked for, if any."""
|
||||
listings = [(flag, getattr(args, flag[2:].replace("-", "_"))) for flag in LISTING_FLAGS]
|
||||
given = {flag for flag, on in (
|
||||
*listings,
|
||||
("--platform", args.platform),
|
||||
("--all", args.all),
|
||||
("--emulator", args.emulator),
|
||||
("--system", args.system),
|
||||
("--region", getattr(args, "region", None)),
|
||||
("--target", getattr(args, "target", None)),
|
||||
("--standalone", args.standalone),
|
||||
("--json", args.json),
|
||||
("--strict", args.strict),
|
||||
("--verbose", args.verbose),
|
||||
("--destinations", args.destinations),
|
||||
("--offline", args.offline),
|
||||
("--no-game-data", getattr(args, "no_game_data", False)),
|
||||
("--required-only", args.required_only),
|
||||
) if on}
|
||||
return refuse_beside_mode(listings, given, LISTING_FLAGS, parser)
|
||||
|
||||
|
||||
def _refuse_mode_flags(args: argparse.Namespace, parser: argparse.ArgumentParser) -> None:
|
||||
"""A flag the chosen mode does not read is refused, never ignored."""
|
||||
for refused, message in (
|
||||
*mode_conflicts(args),
|
||||
(args.destinations and args.system,
|
||||
"--destinations describes the full pack and is incompatible with --system"),
|
||||
(args.destinations and not (args.platform or args.all),
|
||||
"--destinations requires --platform or --all"),
|
||||
(args.destinations and getattr(args, "region", None),
|
||||
"--destinations describes the full pack and is incompatible with --region"),
|
||||
(args.destinations and args.required_only,
|
||||
"--destinations describes the full pack and is incompatible with --required-only"),
|
||||
):
|
||||
if refused:
|
||||
parser.error(message)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = build_parser()
|
||||
with contextlib.ExitStack() as held:
|
||||
_main(held)
|
||||
run_verify(held, parser, parser.parse_args())
|
||||
|
||||
|
||||
def _build_parser() -> argparse.ArgumentParser:
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(allow_abbrev=False, description="Platform-native BIOS verification")
|
||||
parser.add_argument("--platform", "-p", type=platform_arg, help="Platform name")
|
||||
parser.add_argument(
|
||||
@@ -166,131 +102,6 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
return parser
|
||||
|
||||
|
||||
def _check_mode(args: argparse.Namespace, parser: argparse.ArgumentParser) -> bool:
|
||||
"""Refuse a request naming no mode or several, and say if it is the system mode."""
|
||||
_refuse_mode_flags(args, parser)
|
||||
return bool(args.system) and not (args.platform or args.all)
|
||||
|
||||
|
||||
def _run_emulator_mode(args: argparse.Namespace, db: dict, requested_regions: list[str]) -> None:
|
||||
_print_emulator_run(args, verify_emulator(
|
||||
comma_list(args.emulator), args.emulators_dir, db, args.standalone,
|
||||
regions=requested_regions, platforms_dir=args.platforms_dir,
|
||||
required_only=args.required_only,
|
||||
))
|
||||
|
||||
|
||||
def _run_system_mode(args: argparse.Namespace, db: dict, requested_regions: list[str]) -> None:
|
||||
_print_emulator_run(args, verify_system(
|
||||
comma_list(args.system), args.emulators_dir, db, args.standalone,
|
||||
regions=requested_regions, platforms_dir=args.platforms_dir,
|
||||
required_only=args.required_only,
|
||||
))
|
||||
|
||||
|
||||
def _print_emulator_run(args: argparse.Namespace, result: dict) -> None:
|
||||
"""An --emulator or --system result, as text or JSON, then the strict gate."""
|
||||
if args.json:
|
||||
result["details"] = json_details(result["details"], args.verbose)
|
||||
print(json.dumps(result, indent=2))
|
||||
else:
|
||||
print_emulator_result(result, verbose=args.verbose)
|
||||
_exit_if_strict_emulator(args.strict, result)
|
||||
|
||||
|
||||
def _print_platform_results(args: argparse.Namespace, results: PlatformResults) -> None:
|
||||
group_results = results.group_results
|
||||
if not args.json:
|
||||
for result, group in group_results:
|
||||
print_platform_result(result, group, verbose=args.verbose)
|
||||
print()
|
||||
if len(group_results) > 1:
|
||||
print(overall_summary(group_results))
|
||||
|
||||
if args.destinations:
|
||||
write_pack_destinations(args.destinations, results.groups, group_results)
|
||||
|
||||
if args.json:
|
||||
for r in results.all_results.values():
|
||||
r["details"] = json_details(r["details"], args.verbose)
|
||||
print(json.dumps(results.all_results, indent=2))
|
||||
|
||||
|
||||
def _run_platform_mode(
|
||||
args: argparse.Namespace,
|
||||
parser: argparse.ArgumentParser,
|
||||
db: dict,
|
||||
requested_regions: list[str],
|
||||
platform_systems: list[str] | None,
|
||||
) -> None:
|
||||
results = verify_platforms(selected_platforms(args, parser), db, PlatformRun(
|
||||
platforms_dir=args.platforms_dir,
|
||||
emulators_dir=args.emulators_dir,
|
||||
target=args.target,
|
||||
is_all=args.all,
|
||||
regions=requested_regions,
|
||||
system_filter=platform_systems,
|
||||
no_game_data=getattr(args, "no_game_data", False),
|
||||
required_only=args.required_only,
|
||||
))
|
||||
_print_platform_results(args, results)
|
||||
_exit_if_strict(args.strict, [r for r, _ in results.group_results])
|
||||
|
||||
|
||||
def _main(held: contextlib.ExitStack) -> None:
|
||||
parser = _build_parser()
|
||||
args = parser.parse_args()
|
||||
work_from_repo_root(args, parser, ["db", "platforms_dir", "emulators_dir"])
|
||||
if args.platform:
|
||||
require_platform(args.platform, args.platforms_dir)
|
||||
if args.offline:
|
||||
from resolve import packfiles as packresolve
|
||||
|
||||
packresolve.set_offline(True)
|
||||
|
||||
regions = requested_regions(args.region, parser)
|
||||
|
||||
if _refuse_listing_narrowings(args, parser):
|
||||
run_listing(args, parser, args.list_platforms)
|
||||
return
|
||||
|
||||
system_mode = _check_mode(args, parser)
|
||||
platform_systems = resolve_system_ids(args, parser)
|
||||
# The trees stay put while names resolve against them and files are read.
|
||||
from packs.datadirs import hold_data_dirs
|
||||
|
||||
hold_data_dirs(held, load_data_dir_registry(args.platforms_dir))
|
||||
|
||||
db = load_database(args.db)
|
||||
|
||||
if args.emulator:
|
||||
_run_emulator_mode(args, db, regions)
|
||||
return
|
||||
|
||||
if system_mode:
|
||||
_run_system_mode(args, db, regions)
|
||||
return
|
||||
|
||||
# Platform mode (existing)
|
||||
_run_platform_mode(args, parser, db, regions, platform_systems)
|
||||
|
||||
|
||||
def _exit_if_strict(strict: bool, results: list[dict]) -> None:
|
||||
"""Exit 1 under --strict when a platform result counts a critical file."""
|
||||
failure = platform_strict_failure(results)
|
||||
if strict and failure:
|
||||
print(failure, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _exit_if_strict_emulator(strict: bool, result: dict) -> None:
|
||||
"""Exit 1 under --strict when an emulator lacks a file it cannot run without."""
|
||||
failure = emulator_strict_failure(result)
|
||||
if strict and failure:
|
||||
print(failure, file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
from core.cli import run_cli
|
||||
|
||||
|
||||
+3
-2
@@ -26,11 +26,12 @@ COMMANDS = {
|
||||
"verify.py": (
|
||||
"packs/verdicts.py", "packs/gaps.py", "packs/coverage.py", "packs/emulatorcheck.py",
|
||||
"packs/report.py", "packs/verifyplatforms.py", "packs/verifysummary.py",
|
||||
"packs/verifyoutput.py", "packs/strictgate.py",
|
||||
"packs/verifyoutput.py", "packs/strictgate.py", "packs/verifyoptions.py",
|
||||
"packs/verifyprint.py", "packs/verifyrun.py",
|
||||
),
|
||||
"cross_reference.py": (
|
||||
"packs/crossref.py", "packs/crossrefscope.py", "packs/crossrefrun.py",
|
||||
"packs/crossreflaunchers.py", "packs/crossreftext.py",
|
||||
"packs/crossreflaunchers.py", "packs/crossreftext.py", "packs/crossrefreport.py",
|
||||
),
|
||||
"slots.py": ("packs/slots.py", "resolve/collisions.py", "packs/slotscan.py", "packs/slotreport.py"),
|
||||
"validate_pr.py": (
|
||||
|
||||
@@ -4907,7 +4907,7 @@ class TheGapReportKeepsItsShape(unittest.TestCase):
|
||||
--platform totals said "across all emulators"."""
|
||||
|
||||
def test_layout(self):
|
||||
from scripts.cross_reference import print_report
|
||||
from scripts.packs.crossreftext import print_report
|
||||
|
||||
report = {"abuse": {
|
||||
"emulator": "Abuse", "systems": [], "gaps": 1, "total_files": 1,
|
||||
@@ -6676,11 +6676,18 @@ class ReportsHoldTheDataTrees(unittest.TestCase):
|
||||
node for node in tree.body
|
||||
if isinstance(node, ast.FunctionDef) and node.name == "main"
|
||||
)
|
||||
# A thin command holds them in main or in the package run main calls.
|
||||
called = {getattr(call.func, "id", None) for call in ast.walk(main)
|
||||
if isinstance(call, ast.Call)}
|
||||
entry_points = [main] + [
|
||||
node for node in ast.walk(ast.parse(script_source(script)))
|
||||
if isinstance(node, ast.FunctionDef) and node.name in called
|
||||
]
|
||||
with self.subTest(script=script):
|
||||
self.assertTrue(any(
|
||||
isinstance(call, ast.Call)
|
||||
and getattr(call.func, "id", None) == "hold_data_dirs"
|
||||
for call in ast.walk(main)
|
||||
for entry in entry_points for call in ast.walk(entry)
|
||||
))
|
||||
|
||||
|
||||
@@ -6707,7 +6714,7 @@ class TheCliSetsBundledFilesApart(unittest.TestCase):
|
||||
by design and verify and the gaps page already say so."""
|
||||
|
||||
def test_a_bundled_gap_is_not_missing(self):
|
||||
from scripts.cross_reference import print_report
|
||||
from scripts.packs.crossreftext import print_report
|
||||
|
||||
gap = {"name": "n64.psh", "required": True, "bundled": True, "note": "",
|
||||
"source": "missing"}
|
||||
|
||||
@@ -177,7 +177,7 @@ class TheDestinationsFlagNeedsAPack(unittest.TestCase):
|
||||
import ast
|
||||
|
||||
tree = ast.parse(script_source("verify.py"))
|
||||
body = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == "_main")
|
||||
body = next(n for n in tree.body if isinstance(n, ast.FunctionDef) and n.name == "run_verify")
|
||||
stack = body.args.args[0].arg
|
||||
rebound = [
|
||||
node.lineno for node in ast.walk(body)
|
||||
|
||||
Reference in new issue
Block a user