refactor: one owner for a launcher emulator list

The comma-joined emulator field of a launcher record was written in
eleven places and read in nine, four of them splitting on ", " with no
strip. model.launcherrecords joins and splits it, and every scraper,
resolve and packs reader goes through it.
This commit is contained in:
Abdessamad Derraz committed 2026-11-23 21:02:27 +01:00
1 parent 2b5031ecd6
commit 0757698063
19 files changed
+79 -29

No files matched your search

+2 -1
View File
@@ -9,6 +9,7 @@ import posixpath
from collections.abc import Callable
from typing import Any
from model.launcherrecords import join_emulators
from .configgen_launchers import LauncherShapeError, Source, _assigned_name, assigned_value
@@ -159,7 +160,7 @@ class Configgen:
def emulator(self, module: str) -> str:
"""The name configgen loads `module` for (importer.get_generator)."""
if module in self._generators:
return ", ".join(self._generators[module])
return join_emulators(self._generators[module])
package, _, leaf = module.partition(".")
if leaf == f"{package}Generator":
return package
+2 -1
View File
@@ -19,6 +19,7 @@ import re
from collections.abc import Callable, Iterable
from typing import Any
from model.launcherrecords import join_emulators
from .configgen_launchers import (
Launcher,
LauncherShapeError,
@@ -939,7 +940,7 @@ def core_file_options(cg: Configgen) -> list[Launcher]:
src.fail(f"{setting} has no literal default")
depends = option if condition is None else f"{option} (default by {condition})"
launchers.append(Launcher(
emulator=", ".join(cores[function_name]), build="libretro", kind="core_option",
emulator=join_emulators(cores[function_name]), build="libretro", kind="core_option",
names=names, passes_to=f"core option {setting}", depends_on_option=depends,
source_ref=src.ref([src.span(_outermost(function, call))]),
))
+4 -3
View File
@@ -15,6 +15,7 @@ from collections.abc import Callable
from model.database import load_database
from model.launcherrecords import record_emulators
from core.paths import DB_FILE, REPO_ROOT
from model.targets import load_target_config, not_cores
from core.hashing import cut_md5_owner
@@ -425,11 +426,11 @@ def boards_build(selection: BuildSelection, launchers: list[dict]) -> Callable[[
/userdata/bios/pico-8/pico8) needs no package.
"""
supplied = {
name.strip()
name
for record in launchers
if record.get("passes_to") == "exec"
and str(record.get("search_dir") or "").startswith("/userdata/bios")
for name in str(record.get("emulator", "")).split(",")
for name in record_emulators(record)
}
def built(name: str) -> bool:
@@ -471,7 +472,7 @@ def records_run(launchers: list[dict], built: Callable[[str], bool]) -> list[dic
(KNULLI's citron, pcsx2, shadps4): what they read is never read on the
device, so the records do not describe the platform.
"""
return [r for r in launchers if any(built(n) for n in str(r["emulator"]).split(", "))]
return [r for r in launchers if any(built(n) for n in record_emulators(r))]
class CheckBiosScraper(BaseScraper):
+2 -1
View File
@@ -13,6 +13,7 @@ import re
from collections.abc import Iterator
from dataclasses import dataclass, field
from model.launcherrecords import join_emulators
from .batocera_configgen import Configgen, _path_value
from .configgen_launchers import Launcher, Source, _assigned_name, end_line
@@ -502,7 +503,7 @@ def bios_sites(cg: Configgen, spec: GenericSites) -> list[Launcher]:
site.path = site.path[len(flag) + 1:]
emulator = (
spec.emulator
or ", ".join(site.cores or caller_cores)
or join_emulators(site.cores or caller_cores)
or (cg.emulator(module) if spec.build == "standalone" else "")
)
if not emulator:
+2 -1
View File
@@ -17,6 +17,7 @@ import re
from collections.abc import Callable, Iterable
from dataclasses import dataclass, field
from model.launcherrecords import join_emulators
from .configgen_launchers import Launcher
from .rocknix_launchers import fixed_paths
from scraper.shell_launchers import (
@@ -111,7 +112,7 @@ class Runs:
return self.by_script[name]
def emulator(self, name: str) -> str:
return ", ".join(self.of(name).emulators)
return join_emulators(self.of(name).emulators)
def ref(self, name: str) -> tuple[str, set[int]]:
return (RUN_EMU, set(self.of(name).lines))
+2 -1
View File
@@ -27,6 +27,7 @@ Verification (batocera-systems at the release tag):
from __future__ import annotations
from model.sourcerevision import required_revision
from model.launcherrecords import record_emulators
from model.targets import not_cores
from .base_scraper import fetch_github_latest_version, fetch_text
from .batocera_scraper import (
@@ -124,7 +125,7 @@ class Scraper(CheckBiosScraper):
# no ES core name: only a record of an emulator no image carries goes.
launchers = [
r for r in extract_launchers(RepoTree.github(REPO, required_revision(self.url, REPO)))
if not set(str(r["emulator"]).split(", ")) <= unbuilt
if not set(record_emulators(r)) <= unbuilt
]
return {
"platform": "EmuELEC",
+4 -3
View File
@@ -28,6 +28,7 @@ from typing import Any
import yaml
from model.launcherrecords import emulator_names, join_emulators
from .batocera_launchers import (
PATH_PATCHES,
config_directories,
@@ -278,7 +279,7 @@ def core_file_options(cg: Configgen) -> list[Launcher]:
src.fail(f"{setting} is not set under a core test")
depends = setting if not conditions else f"{setting} (default by {', '.join(conditions)})"
launchers.append(Launcher(
emulator=", ".join(_cores_of(holder.test)), build="libretro", kind="core_option",
emulator=join_emulators(_cores_of(holder.test)), build="libretro", kind="core_option",
names=names, passes_to=f"core option {setting}", depends_on_option=depends,
source_ref=src.ref([src.span(holder.test), _lines(chain)]),
))
@@ -476,14 +477,14 @@ def boot_disks(
reader = _Reader(cg, src)
module = spec.path.removesuffix(".py").replace("/", ".")
emulator = (
", ".join(_caller_cores(cg, spec.caller)) if spec.caller else cg.emulator(module)
join_emulators(_caller_cores(cg, spec.caller)) if spec.caller else cg.emulator(module)
)
if spec.caller and spec.feature[:2] == ("libretro", "cores"):
# The option is offered for one core of the system: es_features
# lists it under that core, the other cores the generator serves
# never see it (KNULLI's macintosh offers mame alone).
core = spec.feature[2]
if core not in emulator.split(", "):
if core not in emulator_names(emulator):
src.fail(f"es_features offers the option for {core}, which the generator does not serve")
emulator = core
found = 0
+5 -4
View File
@@ -21,6 +21,7 @@ from dataclasses import dataclass, field
from functools import partial
from typing import Any
from model.launcherrecords import emulator_names, join_emulators
from .configgen_launchers import (
Launcher,
LauncherShapeError,
@@ -249,14 +250,14 @@ class Configgen:
module = module.replace("/", ".")
if module not in self._emulators:
raise LauncherShapeError(f"{LAUNCHER}: no emulator loads {module}")
return ", ".join(self._emulators[module])
return join_emulators(self._emulators[module])
def core(self, function: str) -> str:
"""The libretro cores fillCoresConfiguration hands to `function`."""
cores = _handler_map(self.source(CORES), "fillCoresConfiguration", "specificCoreHandlers")
if function not in cores:
self.source(CORES).fail(f"no core is configured by {function}")
return ", ".join(cores[function])
return join_emulators(cores[function])
def env(self, source: Source, scope: ast.AST | None = None) -> dict[str, Any]:
"""recalboxFiles, the module's class attributes and the strings
@@ -462,7 +463,7 @@ def system_directories(cg: Configgen) -> list[Launcher]:
words = ["core with no case of its own"] + ([condition] if condition else [])
condition = ", ".join(words)
launchers.append(record(
", ".join(cores) or ALL_CORES, condition, call,
join_emulators(cores) or ALL_CORES, condition, call,
[(pattern.lineno, pattern.lineno), (start, end_line(call))],
))
@@ -490,7 +491,7 @@ def system_directories(cg: Configgen) -> list[Launcher]:
def core_directory(directories: list[Launcher], core: str) -> Launcher:
"""The unconditional system_directory record that applies to `core`."""
for launcher in directories:
if core in launcher.emulator.split(", ") and launcher.depends_on_option is None:
if core in emulator_names(launcher.emulator) and launcher.depends_on_option is None:
return launcher
for launcher in directories:
if launcher.emulator == ALL_CORES and launcher.depends_on_option == \
+3 -2
View File
@@ -13,6 +13,7 @@ from __future__ import annotations
import re
from collections.abc import Callable
from model.launcherrecords import join_emulators
from resolve.launcherrefs import is_feature_ref, split_ref
from .csharp_source import (
LauncherPatternMissing,
@@ -1423,7 +1424,7 @@ def _cxbx_mount(src: Source, emulators: list[str]) -> list[Record]:
)
iso_span = src.lines(iso.start(), iso.end())
when = f'rom extension "{iso.group(1)}"'
emulator = ", ".join(emulators)
emulator = join_emulators(emulators)
return [
_record(
emulator,
@@ -2853,7 +2854,7 @@ def capsimg(sources: dict[str, Source]) -> list[Record]:
"capsimg gate",
)
block = src.block_at(gate.end())
[record] = _copies_if_absent(src, ", ".join(names), "libretro", block)
[record] = _copies_if_absent(src, join_emulators(names), "libretro", block)
record["source_ref"] = source_ref(
(src.path, [(src.line(cores.start()), core_lines[1]), src.statement_span(block)])
)