From d295e51ad6efc5ae3bc304fca0028899637c2d0d Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 9 Oct 2026 22:57:15 +0200 Subject: [PATCH] fix: list systems the way --system selects --- scripts/common.py | 21 ++++++++++++++------- tests/test_system_selection.py | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index 1eab0cdd..e3e0d8d1 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -1709,17 +1709,24 @@ def list_emulator_profiles(emulators_dir: str, skip_aliases: bool = True) -> Non def list_system_ids(emulators_dir: str) -> None: - """Print available system IDs with emulator count.""" + """Print available system IDs with emulator count. + + Counted on the normalized id, as --system selects: listed per spelling, + 3do showed two emulators and panasonic-3do six for one system. + """ profiles = load_emulator_profiles(emulators_dir) - system_emus: dict[str, list[str]] = {} - for name, p in profiles.items(): + system_emus: dict[str, set[str]] = {} + spelling: dict[str, str] = {} + for name, p in sorted(profiles.items()): if p.get("type") in ("alias", "test", "launcher"): continue for sys_id in p.get("systems", []): - system_emus.setdefault(sys_id, []).append(name) - for sys_id in sorted(system_emus): - count = len(system_emus[sys_id]) - print(f" {sys_id:35s} ({count} emulator{'s' if count > 1 else ''})") + key = _norm_system_id(sys_id) + system_emus.setdefault(key, set()).add(name) + spelling.setdefault(key, sys_id) + for key in sorted(system_emus, key=lambda k: spelling[k]): + count = len(system_emus[key]) + print(f" {spelling[key]:35s} ({count} emulator{'s' if count > 1 else ''})") def list_platform_system_ids(platform_name: str, platforms_dir: str) -> None: diff --git a/tests/test_system_selection.py b/tests/test_system_selection.py index f594bcb3..916730de 100644 --- a/tests/test_system_selection.py +++ b/tests/test_system_selection.py @@ -40,6 +40,23 @@ class SpellingsAgree(unittest.TestCase): self.assertEqual(builder._system_display_name("msxturboR"), builder._system_display_name("msxturbor")) +class TheListingCountsLikeTheSelection(unittest.TestCase): + def test_one_system_is_listed_once_with_every_profile(self): + import contextlib # noqa: PLC0415 + import io # noqa: PLC0415 + + out = io.StringIO() + with contextlib.redirect_stdout(out): + common.list_system_ids(str(REPO_ROOT / "emulators")) + lines = {line.split()[0]: line for line in out.getvalue().splitlines() if line.strip()} + profiles = common.load_emulator_profiles(str(REPO_ROOT / "emulators")) + for spellings in (("3do", "panasonic-3do"), ("atari-2600", "atari_2600")): + listed = [s for s in spellings if s in lines] + self.assertEqual(len(listed), 1, f"{spellings}: one line per system") + count = len(common.profiles_for_systems(profiles, [spellings[0]])) + self.assertIn(f"({count} emulator", lines[listed[0]]) + + class StandaloneNeedsAStandaloneBuild(unittest.TestCase): def test_a_custom_pack_refuses_it_for_a_libretro_core(self): with tempfile.TemporaryDirectory() as tmp: