fix: advise only a core that --core accepts

The size hint drew from every core of the system and named ares, which
loads no file of its own, so --core ares was refused. It now picks among
the names --core resolves against.
This commit is contained in:
Abdessamad Derraz committed 2026-10-23 13:50:54 +02:00
1 parent 84646d00a6
commit 41839b7784
4 files changed
+34 -5

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@
$ErrorActionPreference = "Stop"
$defaultInstallUrl = "https://raw.githubusercontent.com/Abdess/retrobios/main/install.py"
$defaultInstallSha256 = "1238dfb08b3168992cf4e390358540c6c1bbadf23ae5b74fb34e9101a2a083ef"
$defaultInstallSha256 = "853300c169f08b2554a421aac33da1b5004d3eedd70ae9dec1d732766d06b1ca"
$maximumInstallerBytes = 2MB
$installerExit = 0
$installer = if ($PSScriptRoot) { Join-Path $PSScriptRoot "install.py" } else { $null }
+10 -2
View File
@@ -40,7 +40,7 @@ import urllib.request
import xml.etree.ElementTree as ET
import zipfile
import zlib
from collections.abc import Callable, Iterator
from collections.abc import Callable, Collection, Iterator
from pathlib import Path, PurePosixPath
from typing import BinaryIO, NamedTuple, TextIO
@@ -6607,11 +6607,15 @@ def _bytes(files: list[dict]) -> int:
def bulk_hint(
to_download: list[dict], manifest: dict, systems_chosen: bool, cores_chosen: bool,
accepted: Collection[str] = (),
) -> list[str]:
"""Name what pulls most of a download, when narrowing saves over half of it.
`--system 3do` fetched 349 MB for RetroArch, and `--core opera` 12.5 MB:
the arcade cores that also read 3DO pulled the rest, and nothing said so.
accepted holds the names --core takes. Drawn from every core of the
system, the advice named ares, which loads no file of its own, and
`--core ares` was then refused.
"""
total = _bytes(to_download)
if total < BULK_HINT_FROM:
@@ -6619,7 +6623,8 @@ def bulk_hint(
systems = {s for entry in to_download for s in entry_systems(entry)}
if not cores_chosen and len(systems) == 1:
system = next(iter(systems))
candidates = (manifest.get("system_cores") or {}).get(system) or []
candidates = [core for core in (manifest.get("system_cores") or {}).get(system) or []
if core in accepted]
by_core: dict[str, int] = {}
for entry in to_download:
for core in entry.get("cores") or []:
@@ -7465,6 +7470,8 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None:
args.emulator, manifest, plat_name, files, omitted_files
)
# What --core resolves against, for advice that names one.
core_choices = set(available_choices(files, omitted_files)["cores"])
selection = _requested_narrowing(args, plat_name, files, omitted_files, manifest)
if (
selection is None
@@ -7577,6 +7584,7 @@ def _install(args: argparse.Namespace, real_stdout: TextIO) -> None:
systems_chosen=bool(selection and selection[0]),
cores_chosen=bool((selection and selection[1]) or args.emulator
or args.installed_cores or target),
accepted=core_choices,
)
narrowed = bool(
+1 -1
View File
@@ -18,7 +18,7 @@ esac
TEMP_INSTALLER=""
TEMP_DIRECTORY=""
DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/install.py"
DEFAULT_INSTALL_SHA256="1238dfb08b3168992cf4e390358540c6c1bbadf23ae5b74fb34e9101a2a083ef"
DEFAULT_INSTALL_SHA256="853300c169f08b2554a421aac33da1b5004d3eedd70ae9dec1d732766d06b1ca"
MAX_INSTALLER_BYTES=2097152
cleanup() {
+22 -1
View File
@@ -477,12 +477,33 @@ class TheSummaryNamesTheBulk(unittest.TestCase):
_sized("mame/3do_m2.zip", 37 * MB, ["3do"], ["mame"]),
]
lines = install.bulk_hint(files, {"system_cores": {"3do": ["mame", "opera"]}},
systems_chosen=True, cores_chosen=False)
systems_chosen=True, cores_chosen=False,
accepted={"mame", "opera"})
self.assertEqual(lines, [
" mame pulls 337.0 MB of this 349.0 MB download for 3do. --core opera "
"keeps 12.0 MB of it and saves 337.0 MB (96%)."
])
def test_only_a_core_the_option_accepts_is_advised(self):
"""`--core ares keeps 11.0 MB` was printed, and `--core ares` then
answered "unknown core": ares emulates the PlayStation and loads no
file of its own, and --core takes only the cores that do."""
files = [
_sized("scph5501.bin", 1 * MB, ["sony-playstation"]),
_sized("ps2_bios.bin", 300 * MB, ["sony-playstation"], ["duckstation"]),
_sized("pcsx/extra.bin", 2 * MB, ["sony-playstation"], ["pcsx_rearmed"]),
]
manifest = {"system_cores": {"sony-playstation": ["ares", "duckstation",
"pcsx_rearmed"]}}
lines = install.bulk_hint(files, manifest, True, False,
accepted={"duckstation", "pcsx_rearmed"})
self.assertEqual(len(lines), 1)
self.assertIn("--core pcsx_rearmed keeps 3.0 MB", lines[0])
self.assertNotIn("ares", lines[0])
self.assertEqual(install.bulk_hint(files, manifest, True, False,
accepted={"duckstation"}), [])
self.assertEqual(install.bulk_hint(files, manifest, True, False), [])
def test_a_system_pulling_most_of_the_download_is_named(self):
files = [_sized("a.zip", 400 * MB, ["arcade"]), _sized("b.bin", 50 * MB, ["nes"]),
_sized("c.bin", 10 * MB, ["gba"])]