From ee2e6e80ce846926446eb1d0c5f0c162c0ba0889 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 04:53:54 +0100 Subject: [PATCH] refactor: list the copies of an entry in one place Nine places listed an entry with its alternatives and slot choices by hand. The known core names read only the alternatives, so a core named by a slot choice alone would have counted as unknown. --- install.ps1 | 2 +- install.py | 31 ++++++++++++++++--------------- install.sh | 2 +- install/launchers/index.json | 16 ++++++++-------- installer/choices.py | 6 +++--- installer/cores.py | 6 +++--- installer/diagnosis.py | 5 ++--- installer/manifest.py | 7 ++++++- installer/narrowing.py | 6 +++--- installer/removal.py | 8 +++----- installer/tui_choice.py | 4 ++-- tests/test_install_cores.py | 7 +++++++ 12 files changed, 55 insertions(+), 45 deletions(-) diff --git a/install.ps1 b/install.ps1 index 18c76398b..02c9d9e52 100644 --- a/install.ps1 +++ b/install.ps1 @@ -16,7 +16,7 @@ # and Invoke-WebRequest throws on a cut transfer before the hash is read: # the site's build rewrites this line there (scripts/sitebootstrap.py). $mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." - $defaultInstallSha256 = "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39" + $defaultInstallSha256 = "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. $maximumInstallerBytes = 8MB diff --git a/install.py b/install.py index c4133c944..e848e20a6 100644 --- a/install.py +++ b/install.py @@ -3077,6 +3077,11 @@ SELECTION_FIELDS = ("systems", "regions", "region_groups", "region_system_groups OTHER_SYSTEMS = "other" +def entry_copies(entry: dict) -> list[dict]: + """An entry and every copy another core reads at its place.""" + return [entry, *(entry.get("alternatives") or []), *(entry.get("slot_choices") or [])] + + def _check_root(entry: dict, dest: str, omitted: bool = False) -> None: """root is absent or save, emulator only on a file left out (a path in the emulator's own folder, outside the BIOS tree), and core_folder one @@ -3469,7 +3474,7 @@ def _check_standalone_layouts(data: object, manifest: dict, plat: str) -> dict: sizes = { copy["sha1"]: copy.get("size", 0) for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])] - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])] + for copy in entry_copies(entry) if isinstance(copy, dict) and copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset")) } @@ -6665,9 +6670,8 @@ def known_core_names(manifest: dict) -> set[str]: for cores in (manifest.get("system_cores") or {}).values(): names.update(cores) for entry in [*manifest.get("files", []), *manifest.get("omitted_files", [])]: - names.update(entry.get("cores") or []) - for alternative in entry.get("alternatives", []): - names.update(alternative.get("cores") or []) + for copy in entry_copies(entry): + names.update(copy.get("cores") or []) return names @@ -7211,7 +7215,7 @@ def standalone_entries(manifest: dict, layouts: dict, profile: str) -> list[dict copies = { copy["sha1"]: copy for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])] - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])] + for copy in entry_copies(entry) if copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset")) } result: list[dict] = [] @@ -7257,7 +7261,7 @@ def find_by_hash(files: list[dict], value: str) -> tuple[str, list[dict], bool]: recorded = False seen: set[tuple[str, str]] = set() for entry in files: - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]: + for copy in entry_copies(entry): if kind in copy: recorded = True if str(copy.get(kind, "")).lower() != value: @@ -10299,7 +10303,7 @@ def recorded_axes(files: list[dict], omitted: Iterable[dict] = ()) -> frozenset: # pack built with it does. axes = {"regions", *(["systems"] if systems else [])} if any(copy.get("cores") for entry in files - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]): + for copy in entry_copies(entry)): axes.add("cores") return frozenset(axes) @@ -10317,7 +10321,7 @@ def available_choices(files: list[dict], omitted: list[dict]) -> dict[str, list[ ordered.append(OTHER_SYSTEMS) cores = { c for f in files - for copy in [f, *f.get("alternatives", []), *f.get("slot_choices", [])] + for copy in entry_copies(f) for c in (copy.get("cores") or []) } regions = { @@ -12354,8 +12358,7 @@ def _read_from_folder(label: str) -> FolderIndex: def _copies(entry: dict) -> list[dict]: """Every copy the list knows for an entry: its own, other cores', the platform's declared one.""" - return [entry, *entry.get("alternatives", []), *entry.get("slot_choices", []), - *entry.get("declared_choices", [])] + return [*entry_copies(entry), *entry.get("declared_choices", [])] # id(manifest) -> (manifest, the cores its entries name), read once per list. @@ -20510,8 +20513,7 @@ class Removal(NamedTuple): def _entry_sha1s(entry: dict) -> set[str]: - return {str(copy.get("sha1")) for copy in [entry, *(entry.get("alternatives") or []), - *(entry.get("slot_choices") or [])] + return {str(copy.get("sha1")) for copy in entry_copies(entry) if copy.get("sha1")} @@ -20519,8 +20521,7 @@ def _entry_readers(entry: dict) -> set[str] | None: """The cores that read an entry, None for a file of the platform's own list.""" if entry.get("cores") is None: return None - return {core for copy in [entry, *(entry.get("alternatives") or []), - *(entry.get("slot_choices") or [])] + return {core for copy in entry_copies(entry) for core in copy.get("cores") or ()} @@ -24027,7 +24028,7 @@ def tui_core_sizes(state: TuiState) -> dict[str, str]: extra = [entry for entry in kept if entry.get("cores") is not None] by_core: dict[str, list[dict]] = {} for entry in extra: - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]: + for copy in entry_copies(entry): for core in copy.get("cores") or []: listed = by_core.setdefault(core, []) if not listed or listed[-1] is not entry: diff --git a/install.sh b/install.sh index cae3e3302..37aa16b77 100755 --- a/install.sh +++ b/install.sh @@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins # curl or wget stop on a cut transfer before the hash is read: the site's # build rewrites this line there (scripts/sitebootstrap.py). MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that." -DEFAULT_INSTALL_SHA256="c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39" +DEFAULT_INSTALL_SHA256="24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812" # The pin above refuses any changed byte: this cap only stops a body that # cannot be the installer (a sign-in portal's page) before it is hashed. MAX_INSTALLER_BYTES=8388608 diff --git a/install/launchers/index.json b/install/launchers/index.json index 43b3fec31..8125f7530 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1450086, - "sha256": "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39", + "size": 1449658, + "sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1503711, - "sha256": "c489888589339375e3c62dec4bad0a5a36ab4c8a33c21725b15344099129e709" + "size": 1503283, + "sha256": "5e53ba1ca6d7fe47789b84fe1aaaba50e3752454ffc182389bd83e1f905baca1" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1450086, - "sha256": "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39", + "size": 1449658, + "sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1450086, - "sha256": "c11a387a05a77fd98ad147971abf8ab12bb3caff592f8c28e894adaf57fefa39", + "size": 1449658, + "sha256": "24615e6f97626cda0547af94f94334e5964b99ce065c2d4fd3455c8782276812", "executable": false }, { diff --git a/installer/choices.py b/installer/choices.py index 0edc89590..8f3e63ad7 100644 --- a/installer/choices.py +++ b/installer/choices.py @@ -8,7 +8,7 @@ from typing import TYPE_CHECKING from installer.console import detail from installer.install_record import drop_recorded -from installer.manifest import OTHER_SYSTEMS +from installer.manifest import OTHER_SYSTEMS, entry_copies from installer.narrowing import _filter_by_target, designated_cores, narrow, narrow_to_cores, standalone_layout from installer.network import _pack_alone, fetch_standalone from installer.offline import LOCAL @@ -46,7 +46,7 @@ def recorded_axes(files: list[dict], omitted: Iterable[dict] = ()) -> frozenset: # pack built with it does. axes = {"regions", *(["systems"] if systems else [])} if any(copy.get("cores") for entry in files - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]): + for copy in entry_copies(entry)): axes.add("cores") return frozenset(axes) @@ -64,7 +64,7 @@ def available_choices(files: list[dict], omitted: list[dict]) -> dict[str, list[ ordered.append(OTHER_SYSTEMS) cores = { c for f in files - for copy in [f, *f.get("alternatives", []), *f.get("slot_choices", [])] + for copy in entry_copies(f) for c in (copy.get("cores") or []) } regions = { diff --git a/installer/cores.py b/installer/cores.py index d40d5112f..c89b343dd 100644 --- a/installer/cores.py +++ b/installer/cores.py @@ -12,6 +12,7 @@ from installer.frontend_folders import _retroarch_config_for from installer.host_fs import _is_file, closed_folder from installer.invocation import _INVOCATION from installer.local_check import closed_folder_words +from installer.manifest import entry_copies from installer.platforms import display_name from installer.text import _plural, screen_text @@ -133,9 +134,8 @@ def known_core_names(manifest: dict) -> set[str]: for cores in (manifest.get("system_cores") or {}).values(): names.update(cores) for entry in [*manifest.get("files", []), *manifest.get("omitted_files", [])]: - names.update(entry.get("cores") or []) - for alternative in entry.get("alternatives", []): - names.update(alternative.get("cores") or []) + for copy in entry_copies(entry): + names.update(copy.get("cores") or []) return names diff --git a/installer/diagnosis.py b/installer/diagnosis.py index 0415fe68d..07636a8f9 100644 --- a/installer/diagnosis.py +++ b/installer/diagnosis.py @@ -16,7 +16,7 @@ from installer.from_folders import ( _place_reason, ) from installer.host_fs import _is_file -from installer.manifest import GAME_DATA +from installer.manifest import GAME_DATA, entry_copies from installer.paths import _entry_path, shown_path from installer.platforms import entry_systems from installer.regions import WORLD_REGION @@ -29,8 +29,7 @@ if TYPE_CHECKING: def _copies(entry: dict) -> list[dict]: """Every copy the list knows for an entry: its own, other cores', the platform's declared one.""" - return [entry, *entry.get("alternatives", []), *entry.get("slot_choices", []), - *entry.get("declared_choices", [])] + return [*entry_copies(entry), *entry.get("declared_choices", [])] # id(manifest) -> (manifest, the cores its entries name), read once per list. diff --git a/installer/manifest.py b/installer/manifest.py index cd5887575..024c0651f 100644 --- a/installer/manifest.py +++ b/installer/manifest.py @@ -46,6 +46,11 @@ SELECTION_FIELDS = ("systems", "regions", "region_groups", "region_system_groups OTHER_SYSTEMS = "other" +def entry_copies(entry: dict) -> list[dict]: + """An entry and every copy another core reads at its place.""" + return [entry, *(entry.get("alternatives") or []), *(entry.get("slot_choices") or [])] + + def _check_root(entry: dict, dest: str, omitted: bool = False) -> None: """root is absent or save, emulator only on a file left out (a path in the emulator's own folder, outside the BIOS tree), and core_folder one @@ -438,7 +443,7 @@ def _check_standalone_layouts(data: object, manifest: dict, plat: str) -> dict: sizes = { copy["sha1"]: copy.get("size", 0) for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])] - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])] + for copy in entry_copies(entry) if isinstance(copy, dict) and copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset")) } diff --git a/installer/narrowing.py b/installer/narrowing.py index 98d592bb4..ce2d0d21b 100644 --- a/installer/narrowing.py +++ b/installer/narrowing.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections.abc import Callable, Collection -from installer.manifest import FILE_GROUP, OTHER_SYSTEMS, _COPY_FIELDS +from installer.manifest import FILE_GROUP, OTHER_SYSTEMS, _COPY_FIELDS, entry_copies from installer.paths import _entry_key from installer.platforms import entry_systems from installer.regions import WORLD_REGION, _region_rank @@ -467,7 +467,7 @@ def standalone_entries(manifest: dict, layouts: dict, profile: str) -> list[dict copies = { copy["sha1"]: copy for entry in [*manifest.get("files", []), *(manifest.get("truth_files") or [])] - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])] + for copy in entry_copies(entry) if copy.get("sha1") and (copy.get("repo_path") or copy.get("release_asset")) } result: list[dict] = [] @@ -513,7 +513,7 @@ def find_by_hash(files: list[dict], value: str) -> tuple[str, list[dict], bool]: recorded = False seen: set[tuple[str, str]] = set() for entry in files: - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]: + for copy in entry_copies(entry): if kind in copy: recorded = True if str(copy.get(kind, "")).lower() != value: diff --git a/installer/removal.py b/installer/removal.py index 055549c89..8e3accb8f 100644 --- a/installer/removal.py +++ b/installer/removal.py @@ -36,7 +36,7 @@ from installer.install_record import ( ) from installer.invocation import _INVOCATION, offline_requested from installer.local_check import _digest_file -from installer.manifest import OTHER_SYSTEMS, _validate_manifest +from installer.manifest import OTHER_SYSTEMS, _validate_manifest, entry_copies from installer.narrowing import designated_cores from installer.network import _fetch_json, fetch_manifest from installer.paths import shown_path, spelled @@ -89,8 +89,7 @@ class Removal(NamedTuple): def _entry_sha1s(entry: dict) -> set[str]: - return {str(copy.get("sha1")) for copy in [entry, *(entry.get("alternatives") or []), - *(entry.get("slot_choices") or [])] + return {str(copy.get("sha1")) for copy in entry_copies(entry) if copy.get("sha1")} @@ -98,8 +97,7 @@ def _entry_readers(entry: dict) -> set[str] | None: """The cores that read an entry, None for a file of the platform's own list.""" if entry.get("cores") is None: return None - return {core for copy in [entry, *(entry.get("alternatives") or []), - *(entry.get("slot_choices") or [])] + return {core for copy in entry_copies(entry) for core in copy.get("cores") or ()} diff --git a/installer/tui_choice.py b/installer/tui_choice.py index f83ccdcd9..f46a2f5ed 100644 --- a/installer/tui_choice.py +++ b/installer/tui_choice.py @@ -13,7 +13,7 @@ from installer.destination import dest_drive, on_its_card, shown_bios_folder from installer.embedded import CARD_PLATFORMS from installer.frontend_folders import save_directory_for, save_where_words from installer.games import GAMES_REASONS -from installer.manifest import OTHER_SYSTEMS +from installer.manifest import OTHER_SYSTEMS, entry_copies from installer.narrowing import narrow from installer.offline import LOCAL, _offline_only from installer.pack_source import pack_holds_trees, pack_lacks @@ -92,7 +92,7 @@ def tui_core_sizes(state: TuiState) -> dict[str, str]: extra = [entry for entry in kept if entry.get("cores") is not None] by_core: dict[str, list[dict]] = {} for entry in extra: - for copy in [entry, *entry.get("alternatives", []), *entry.get("slot_choices", [])]: + for copy in entry_copies(entry): for core in copy.get("cores") or []: listed = by_core.setdefault(core, []) if not listed or listed[-1] is not entry: diff --git a/tests/test_install_cores.py b/tests/test_install_cores.py index ecd57bbb3..572f0feb3 100644 --- a/tests/test_install_cores.py +++ b/tests/test_install_cores.py @@ -203,6 +203,13 @@ class ACoreTheListDoesNotKnow(unittest.TestCase): ["parallel_dc"], ) + def test_a_core_named_by_a_slot_choice_is_known(self): + listing = {**MANIFEST, "files": [*MANIFEST["files"], { + "dest": "dc/dc_boot.bin", "cores": None, "systems": ["sega-dreamcast"], + "slot_choices": [{"sha1": "0" * 40, "cores": ["flycast"]}]}]} + self.assertEqual(install.unknown_cores(listing, ["flycast", "parallel_dc"]), + ["parallel_dc"]) + def test_the_info_paths_retroarch_reads(self): (self.tmp / "parallel_dc_libretro.info").write_text( 'firmware_count = 3\n'