From 71776198e91e808b299949c7a7cbdaeb807f9f6a Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:20:25 +0100 Subject: [PATCH] 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. --- .github/workflows/deploy-site.yml | 1 + scripts/model/profilekinds.py | 23 +++++++++++++++++++++++ scripts/model/profiles.py | 24 +++--------------------- scripts/model/systems.py | 3 ++- scripts/sitegen/build.py | 4 ++-- 5 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 scripts/model/profilekinds.py diff --git a/.github/workflows/deploy-site.yml b/.github/workflows/deploy-site.yml index f47f6371d..22ecd4ab4 100644 --- a/.github/workflows/deploy-site.yml +++ b/.github/workflows/deploy-site.yml @@ -54,6 +54,7 @@ on: - "scripts/model/nodedup.py" - "scripts/model/platforms.py" - "scripts/model/profiles.py" + - "scripts/model/profilekinds.py" - "scripts/model/region.py" - "scripts/model/registry.py" - "scripts/model/releaserecord.py" diff --git a/scripts/model/profilekinds.py b/scripts/model/profilekinds.py new file mode 100644 index 000000000..96651800e --- /dev/null +++ b/scripts/model/profilekinds.py @@ -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" diff --git a/scripts/model/profiles.py b/scripts/model/profiles.py index 28308fd4f..2786ed805 100644 --- a/scripts/model/profiles.py +++ b/scripts/model/profiles.py @@ -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.""" diff --git a/scripts/model/systems.py b/scripts/model/systems.py index 00876f29a..035b713c5 100644 --- a/scripts/model/systems.py +++ b/scripts/model/systems.py @@ -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) diff --git a/scripts/sitegen/build.py b/scripts/sitegen/build.py index 05aa2a4e8..eda1cabe0 100644 --- a/scripts/sitegen/build.py +++ b/scripts/sitegen/build.py @@ -20,7 +20,7 @@ from model.composition import compute_composition from model.database import load_database from model.dumpcatalog import load_provenance_snapshots from model.guides import HANDHELD_GUIDE -from model.profiles import is_emulator, load_emulator_profiles +from model.profiles import is_emulator, lists_files, load_emulator_profiles from model.registry import list_registered_platforms, load_platform_registry from model.systemnames import program_names, set_console_sections, system_name from packs.crossref import FileConsumers @@ -433,7 +433,7 @@ def _write_emulator_page(run: _SiteRun, name: str, profile: dict) -> None: # A frozen copy answers after the emulator: a frozen_snapshot, and a # profile pinned to the revision one platform builds (pin_frozen). # Reicast and Flycast 2021 LE answered "dc bios missing" before Flycast. - if (profile.get("type") in ("launcher", "alias") + if (not lists_files(profile) or profile.get("core_classification") in ("launcher", "alias", "frozen_snapshot") or profile.get("pin_frozen")): SEARCH_DEMOTED.add(f"emulators/{name}.md")