fix: name the platform a typo was meant to be

This commit is contained in:
Abdessamad Derraz committed 2026-10-17 12:28:27 +02:00
1 parent 2645626684
commit b6331a765a
5 files changed
+49

No files matched your search

+18
View File
@@ -350,6 +350,24 @@ def list_registered_platforms(
return platforms
def require_platform(name: str, platforms_dir: str = "platforms") -> None:
"""Exit with a usable message when no platform answers to a name.
A typo used to end in a traceback (verify, cross_reference) or in "no
pack for batocra" after the whole build ran (generate_pack).
"""
if os.path.exists(os.path.join(platforms_dir, f"{name}.yml")):
return
import difflib # noqa: PLC0415
known = list_registered_platforms(platforms_dir, include_archived=True)
close = difflib.get_close_matches(name, known, n=1)
hint = f" Did you mean '{close[0]}'?" if close else ""
raise SystemExit(
f"ERROR: unknown platform '{name}'.{hint}\nKnown platforms: {', '.join(known)}"
)
def _target_overrides(platform_name: str, targets_dir: str) -> dict:
overrides_file = os.path.join(targets_dir, "_overrides.yml")
if not os.path.exists(overrides_file):
+3
View File
@@ -20,6 +20,7 @@ from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from common import (
require_platform,
_norm_system_id,
directory_members,
get_mame_clone_map,
@@ -642,6 +643,8 @@ def main():
parser.add_argument("--target", "-t", help="Hardware target (e.g., switch, rpi4)")
parser.add_argument("--json", action="store_true", help="JSON output")
args = parser.parse_args()
if args.platform:
require_platform(args.platform, args.platforms_dir)
profiles = load_emulator_profiles(args.emulators_dir)
if args.emulator:
+4
View File
@@ -30,6 +30,7 @@ from pathlib import Path
sys.path.insert(0, os.path.dirname(__file__))
from common import resolve_platform_cores as _platform_cores
from common import (
require_platform,
apply_target_overrides,
archive_entry,
profiles_for_systems,
@@ -2846,6 +2847,9 @@ def main():
)
args = parser.parse_args()
packresolve.set_offline(bool(args.offline))
if args.platform:
for name in args.platform.split(","):
require_platform(name.strip(), args.platforms_dir)
_refuse_unapplied_flags(args, parser)
if args.target:
+3
View File
@@ -34,6 +34,7 @@ import slots
sys.path.insert(0, os.path.dirname(__file__))
from common import (
require_platform,
archive_entry,
archive_members,
profiles_for_systems,
@@ -2064,6 +2065,8 @@ def main():
)
parser.add_argument("--json", action="store_true", help="JSON output")
args = parser.parse_args()
if args.platform:
require_platform(args.platform, args.platforms_dir)
requested_regions: list[str] = []
if getattr(args, "region", None):
+21
View File
@@ -89,5 +89,26 @@ class ADeclinedBuildIsAFailure(unittest.TestCase):
self.assertEqual([p for p in os.listdir(tmp) if p.endswith(".zip")], [])
class AMistypedPlatformIsNamed(unittest.TestCase):
"""verify and cross_reference ended a typo on a traceback; generate_pack
ran its whole build first and then said "no pack for batocra"."""
def test_every_cli_names_the_platform_it_meant(self):
out = Path(tempfile.mkdtemp(dir=REPO_ROOT / "tmp"))
out.rmdir()
for script, extra in (("verify.py", []), ("cross_reference.py", []),
("generate_pack.py", ["--offline", "--output-dir", str(out)])):
with self.subTest(script=script):
proc = subprocess.run(
[sys.executable, f"scripts/{script}", "--platform", "batocra", *extra],
capture_output=True, text=True, cwd=str(REPO_ROOT), timeout=300,
check=False,
)
self.assertNotEqual(proc.returncode, 0)
self.assertNotIn("Traceback", proc.stderr, proc.stderr)
self.assertIn("Did you mean 'batocera'?", proc.stderr)
self.assertFalse(out.exists())
if __name__ == "__main__":
unittest.main()