From 609710e2d76528c6957c60008ff2d1bc2149fbdd Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:42:46 +0100 Subject: [PATCH] fix: say a platform has no hardware targets The error named platforms/targets/.yml, which read as a file missing from the repository (finding 63). --- scripts/common.py | 9 ++++++++- tests/test_tool_messages.py | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 231e835d6..000e0404b 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -664,8 +664,15 @@ def load_target_config( targets_dir = os.path.join(platforms_dir, "targets") target_file = os.path.join(targets_dir, f"{platform_name}.yml") if not os.path.exists(target_file): + # The expected state for a platform that ships one build, said as + # such: the file path read like a file missing from the repository. + with_targets = sorted( + Path(f).stem for f in os.listdir(targets_dir) + if f.endswith(".yml") and not f.startswith("_") + ) raise FileNotFoundError( - f"No target config for platform '{platform_name}': {target_file}" + f"{platform_name} has no hardware targets: drop --target " + f"(platforms with targets: {', '.join(with_targets)})" ) with open(target_file) as f: data = yaml_load(f) or {} diff --git a/tests/test_tool_messages.py b/tests/test_tool_messages.py index 66438844e..ccbf9ddc7 100644 --- a/tests/test_tool_messages.py +++ b/tests/test_tool_messages.py @@ -168,9 +168,6 @@ class HeldButNotPackedNamesEachReason(unittest.TestCase): "in_pack": False, "omitted": reason, "category": category} def _printed(self, entries: list[dict]) -> str: - import contextlib # noqa: PLC0415 - import io # noqa: PLC0415 - out = io.StringIO() with contextlib.redirect_stdout(out): verify._print_undeclared_section({"undeclared_files": entries}, False) @@ -219,6 +216,25 @@ class HeldButNotPackedNamesEachReason(unittest.TestCase): self.assertIn("Core files held but not packed: 2 (installed with its emulator)", text) +class APlatformWithoutTargetsSaysSo(unittest.TestCase): + """`--platform misterfpga --target switch` printed 'No target config for + platform 'misterfpga': platforms/targets/misterfpga.yml', which reads as + a file missing from the repository.""" + + def test_the_message_names_the_reason_and_the_platforms_with_targets(self): + with tempfile.TemporaryDirectory() as tmp: + (Path(tmp) / "targets").mkdir() + for name in ("retroarch", "batocera", "_overrides"): + (Path(tmp) / "targets" / f"{name}.yml").write_text("targets: {}\n") + with self.assertRaises(FileNotFoundError) as caught: + common.load_target_config("misterfpga", "switch", tmp) + self.assertEqual( + str(caught.exception), + "misterfpga has no hardware targets: drop --target " + "(platforms with targets: batocera, retroarch)", + ) + + class OneSpellingPerOption(unittest.TestCase): """verify.py -p batocera worked and slots.py -p batocera was refused."""