Files
libretro/scripts/profiling/flagchecks.py
T
Abdessamad Derraz b520e48798 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.
2026-11-21 15:47:20 +01:00

121 lines
4.8 KiB
Python

"""The flag combinations a profile pass refuses before any request."""
from __future__ import annotations
import argparse
import sys
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)