refactor: move profile kinds to their own module

model.systems kept an inline copy of reads_own_files because model.profiles imports it. The predicates live in model.profilekinds, which both import, and model.profiles re-exports them. sitegen.build reads lists_files instead of its own launcher/alias tuple.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:29:37 +01:00
1 parent 780d40fb7b
commit 71776198e9
5 files changed
+31 -24

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
"""What kind of profile a profile is: an emulator, an alias, a launcher, a test core."""
from __future__ import annotations
# A launcher hands the game to another emulator and an alias is another
# profile's build under a second name: neither declares files of its own.
FILELESS_TYPES = frozenset({"launcher", "alias"})
def lists_files(profile: dict) -> bool:
"""Whether a profile declares the files its emulator reads."""
return profile.get("type") not in FILELESS_TYPES
def is_emulator(profile: dict) -> bool:
"""Whether a profile counts as an emulator of its own, neither an alias
nor a test core."""
return profile.get("type") != "alias" and profile.get("role") != "test"
def reads_own_files(profile: dict) -> bool:
"""Whether a profile lists the files its emulator reads and is not a test core."""
return lists_files(profile) and profile.get("role") != "test"
+3 -21
View File
@@ -14,6 +14,9 @@ except ImportError:
from core.cli import InputMissing, suggest_names
from model.alternatives import derive_member_requirements
from model.profilekinds import is_emulator as is_emulator
from model.profilekinds import lists_files as lists_files
from model.profilekinds import reads_own_files as reads_own_files
from model.sources import source_yaml_file
from model.systems import norm_system_id, system_index
from core.paths import REPO_ROOT
@@ -27,27 +30,6 @@ CONTENT_CHECKS = frozenset({"romdir", "masked_sha1"})
emulator_profiles_cache: dict[tuple[str, bool], dict[str, dict]] = {}
# A launcher hands the game to another emulator and an alias is another
# profile's build under a second name: neither declares files of its own.
FILELESS_TYPES = frozenset({"launcher", "alias"})
def lists_files(profile: dict) -> bool:
"""Whether a profile declares the files its emulator reads."""
return profile.get("type") not in FILELESS_TYPES
def is_emulator(profile: dict) -> bool:
"""Whether a profile counts as an emulator of its own, neither an alias
nor a test core."""
return profile.get("type") != "alias" and profile.get("role") != "test"
def reads_own_files(profile: dict) -> bool:
"""Whether a profile lists the files its emulator reads and is not a test core."""
return lists_files(profile) and profile.get("role") != "test"
class ProfileSelectionError(ValueError):
"""A named profile cannot answer for itself."""
+2 -1
View File
@@ -7,6 +7,7 @@ import re
from core.cli import suggest_names
from model.platforms import native_layer
from model.profilekinds import reads_own_files
MANUFACTURER_PREFIXES = (
@@ -332,7 +333,7 @@ def system_index(profiles: dict) -> dict[str, tuple[str, set[str]]]:
"""
index: dict[str, tuple[str, set[str]]] = {}
for name, p in sorted(profiles.items()):
if p.get("type") in ("alias", "launcher") or p.get("role") == "test":
if not reads_own_files(p):
continue
for sys_id in p.get("systems", []):
key = norm_system_id(sys_id)