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

+25
View File
@@ -0,0 +1,25 @@
"""The emulator field of a platform launcher record: one name, or several joined."""
from __future__ import annotations
from collections.abc import Iterable, Mapping
from typing import Any
# A record written once for several emulators names them all in one field
# (schemas/platform.schema.json, launchers[].emulator).
SEPARATOR = ", "
def join_emulators(names: Iterable[str]) -> str:
"""The emulator field of a record written for `names`."""
return SEPARATOR.join(names)
def emulator_names(field: str) -> list[str]:
"""The names an emulator field joins, in their order."""
return [name.strip() for name in field.split(",")]
def record_emulators(record: Mapping[str, Any]) -> list[str]:
"""The emulators a launcher record is written for."""
return emulator_names(str(record.get("emulator", "")))