mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 18:17:53 -06:00
refactor: move profile selection into profiling
select_profiles and version_selection go to profiling.selection, the flag refusals to profiling.flagchecks. main calls selection, quota and the profile loader through their modules, so tests patch them there. generate_truth's parse_args becomes build_parser.
This commit is contained in:
1 parent
8afccc3d0f
commit
b520e48798
8 files changed
+241
-219
No files matched your search
+10
-193
@@ -16,16 +16,16 @@ import sys
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from core import upstream
|
||||
from model.systems import norm_system_id, system_index
|
||||
from model.profiles import ProfileSelectionError, is_emulator, load_emulator_profiles, resolve_profile_name
|
||||
from core.cli import add_repo_inputs, suggest_names
|
||||
from model import profiles as emulator_profiles
|
||||
from core.cli import add_repo_inputs
|
||||
from profiling import quota, selection
|
||||
from profiling.bump import DEFAULT_CACHE
|
||||
from profiling.quota import check_quota
|
||||
from profiling.flagchecks import refuse_flag_combinations
|
||||
from profiling.realignpass import run_realign
|
||||
from profiling.run import emit_reports, read_selected
|
||||
from profiling.sourcepaths import refresh_source_paths
|
||||
from profiling.versioncheck import run_versions
|
||||
from profiling.worktree import branch_profiles, project_base, refuse_dirty_tree
|
||||
from profiling.worktree import refuse_dirty_tree
|
||||
|
||||
|
||||
def build_parser() -> argparse.ArgumentParser:
|
||||
@@ -179,203 +179,20 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
return parser
|
||||
|
||||
|
||||
def select_profiles(profiles: dict, args: argparse.Namespace) -> dict:
|
||||
"""Profiles matching the selection flags."""
|
||||
if args.changed or args.added:
|
||||
base = args.base or project_base()
|
||||
names = branch_profiles(args.emulators_dir, base, args.added)
|
||||
selected = {name: profiles[name] for name in names if name in profiles}
|
||||
if not selected:
|
||||
verb = "adds" if args.added else "adds or edits"
|
||||
print(f"the branch {verb} no profile against {base}", file=sys.stderr)
|
||||
return selected
|
||||
if args.emulator:
|
||||
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:
|
||||
# by normalized id, so `saturn` reaches the profiles declaring sega-saturn.
|
||||
wanted_system = norm_system_id(args.system) if args.system else None
|
||||
selected = {}
|
||||
for name, profile in sorted(profiles.items()):
|
||||
if not is_emulator(profile):
|
||||
continue
|
||||
if wanted_system and wanted_system not in {
|
||||
norm_system_id(str(s)) for s in profile.get("systems") or []
|
||||
}:
|
||||
continue
|
||||
if args.type_ and profile.get("type") != args.type_:
|
||||
continue
|
||||
if args.stale_before:
|
||||
profiled = str(profile.get("profiled_date") or "")
|
||||
if not profiled or profiled >= args.stale_before:
|
||||
continue
|
||||
selected[name] = profile
|
||||
if args.limit and len(selected) >= args.limit:
|
||||
break
|
||||
if not selected:
|
||||
# A misspelt filter selected nothing and the run said nothing: it
|
||||
# read as "no profile of that system needs a re-read".
|
||||
filters = ", ".join(
|
||||
f"{flag} {value}" for flag, value in (
|
||||
("--system", args.system), ("--type", args.type_),
|
||||
("--stale-before", args.stale_before),
|
||||
) if value
|
||||
)
|
||||
hint = ""
|
||||
if args.system:
|
||||
# Suggested from the spellings the named listing prints.
|
||||
systems = sorted(spelling for spelling, _ in system_index(profiles).values())
|
||||
hint = " " + suggest_names([args.system], systems, "python scripts/verify.py --list-systems")
|
||||
elif args.type_:
|
||||
kinds = sorted({str(p.get("type")) for p in profiles.values() if p.get("type")})
|
||||
hint = f" Types: {', '.join(kinds)}."
|
||||
raise SystemExit(f"ERROR: no profile matches {filters or 'the selection'}.{hint}")
|
||||
return selected
|
||||
|
||||
|
||||
def _refuse_flag_combinations(args: argparse.Namespace) -> None:
|
||||
"""Exit on a flag the chosen mode would not apply, before any request."""
|
||||
if args.verify_version or args.set_version:
|
||||
ignored = [
|
||||
flag for flag, on in (
|
||||
("--verify-version", args.verify_version and args.set_version),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
("--strict", args.strict),
|
||||
("--check-version", args.check_version),
|
||||
("--detect-new-files", args.detect_new_files),
|
||||
("--watch-hashes", args.watch_hashes),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
("--backfill-commits", args.backfill_commits),
|
||||
("--rebase-refs", args.rebase_refs),
|
||||
("--attribute-refs", args.attribute_refs),
|
||||
("--bump-commit", args.bump_commit),
|
||||
("--realign-prose", args.realign_prose),
|
||||
("--accept-changed", args.accept_changed),
|
||||
("--dry-run", args.dry_run and not args.set_version),
|
||||
) if on
|
||||
]
|
||||
if ignored:
|
||||
mode = "--set-version" if args.set_version else "--verify-version"
|
||||
print(f"{mode} does not apply {', '.join(ignored)}", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
if args.fresh and args.offline:
|
||||
print("--fresh asks the forges again, which --offline forbids.", file=sys.stderr)
|
||||
raise SystemExit(1)
|
||||
if args.accept_changed and not args.emulator:
|
||||
print(
|
||||
"--accept-changed applies to one profile at a time: its diff has "
|
||||
"to be read before its CHANGED refs can be recaled.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.attribute_refs and (
|
||||
args.rebase_refs or args.bump_commit or args.backfill_commits
|
||||
or args.realign_prose
|
||||
):
|
||||
print(
|
||||
"--attribute-refs runs alone: it rewrites the refs the report was "
|
||||
"built from.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.realign_prose and (
|
||||
args.rebase_refs or args.bump_commit or args.backfill_commits
|
||||
):
|
||||
print(
|
||||
"--realign-prose runs alone: the report has to be rebuilt on the "
|
||||
"realigned text before any other write.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
if args.realign_prose:
|
||||
ignored = [
|
||||
flag for flag, on in (
|
||||
("--json", args.as_json),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
("--changed-only", args.changed_only),
|
||||
("--strict", args.strict),
|
||||
("--check-version", args.check_version),
|
||||
("--detect-new-files", args.detect_new_files),
|
||||
("--watch-hashes", args.watch_hashes),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
("--accept-changed", args.accept_changed),
|
||||
) if on
|
||||
]
|
||||
if ignored:
|
||||
# A mode applies a flag or refuses it, never swallows it.
|
||||
print(
|
||||
f"--realign-prose does not apply {', '.join(ignored)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
machine = [
|
||||
flag for flag, on in (
|
||||
("--json", args.as_json),
|
||||
("--markdown", args.markdown),
|
||||
("--fetch-plan", args.fetch_plan),
|
||||
("--triage", args.triage),
|
||||
) if on
|
||||
]
|
||||
# The version check lives on the report, so the outputs built from the
|
||||
# report (text, --json, --markdown) carry it. A URL list and a ranking
|
||||
# do not. Detection lives on the report too, and --json carries it for
|
||||
# check_freshness. The markdown table has no column for it.
|
||||
lists_only = args.fetch_plan or args.triage
|
||||
off_json = lists_only or args.markdown
|
||||
extras = [
|
||||
flag for flag, on in (
|
||||
("--check-version", args.check_version and lists_only),
|
||||
("--detect-new-files", args.detect_new_files and off_json),
|
||||
("--watch-hashes", args.watch_hashes and off_json),
|
||||
("--full-diff", args.full_diff),
|
||||
("--tree-diff", args.tree_diff),
|
||||
) if on
|
||||
]
|
||||
if machine and extras:
|
||||
# The extra sections only exist in the text report. The other outputs
|
||||
# returned before reaching them and printed as if never asked.
|
||||
print(
|
||||
f"{', '.join(machine)} does not carry {', '.join(extras)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
raise SystemExit(1)
|
||||
|
||||
|
||||
def _version_selection(args: argparse.Namespace, profiles: dict) -> dict:
|
||||
"""--all reaches the alias and test profiles too: each states a version."""
|
||||
if args.all and not (args.system or args.type_ or args.stale_before or args.limit):
|
||||
return dict(sorted(profiles.items()))
|
||||
return select_profiles(profiles, args)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Build one report per selected profile, then apply writes and output."""
|
||||
args = build_parser().parse_args()
|
||||
_refuse_flag_combinations(args)
|
||||
refuse_flag_combinations(args)
|
||||
if args.fresh:
|
||||
# Tips cached before an upstream commit hid it for six hours: EKA2L1,
|
||||
# trzy/Supermodel and VICE read as behind their real HEAD.
|
||||
upstream.MOVING_TTL = 0
|
||||
profiles = load_emulator_profiles(args.emulators_dir, skip_aliases=False)
|
||||
profiles = emulator_profiles.load_emulator_profiles(args.emulators_dir, skip_aliases=False)
|
||||
if args.verify_version or args.set_version:
|
||||
run_versions(args, profiles, _version_selection(args, profiles))
|
||||
run_versions(args, profiles, selection.version_selection(args, profiles))
|
||||
return
|
||||
selected = select_profiles(profiles, args)
|
||||
check_quota(len(selected), args.offline)
|
||||
selected = selection.select_profiles(profiles, args)
|
||||
quota.check_quota(len(selected), args.offline)
|
||||
|
||||
writes = (
|
||||
args.backfill_commits or args.rebase_refs or args.bump_commit
|
||||
|
||||
Reference in new issue
Block a user