mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
refactor: share CLI options and default paths
core.paths holds the default database, platforms, emulators and bios paths, core.cli declares the options built on them (add_repo_inputs) and the --emulator/--system modes verify and generate_pack share. model.targets.target_scope answers --target for a command line, model.profiles.no_profile_for_systems the system with no emulator. tests/sources.declared_options reads the options a script declares through either form.
This commit is contained in:
1 parent
348d5b51c3
commit
cf03dcb2ef
50 files changed
+260
-405
No files matched your search
@@ -16,7 +16,7 @@ from model.platforms import load_platform_config
|
||||
from model.profiles import load_emulator_profiles
|
||||
from model.registry import list_registered_platforms, list_release_pack_platforms
|
||||
from model.systems import platform_system_names, system_index
|
||||
from core.paths import REPO_ROOT
|
||||
from core.paths import PLATFORMS_DIR, REPO_ROOT
|
||||
|
||||
|
||||
def work_from_repo_root(
|
||||
@@ -62,7 +62,7 @@ def platform_arg(value: str) -> str:
|
||||
return value
|
||||
|
||||
|
||||
def require_platform(name: str, platforms_dir: str = "platforms") -> None:
|
||||
def require_platform(name: str, platforms_dir: str = PLATFORMS_DIR) -> None:
|
||||
"""Exit with a usable message when no platform answers to a name.
|
||||
|
||||
A typo used to end in a traceback (verify, cross_reference) or in "no
|
||||
|
||||
@@ -9,6 +9,7 @@ try:
|
||||
except ImportError:
|
||||
yaml = None
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from model.sources import source_yaml
|
||||
|
||||
|
||||
@@ -181,7 +182,7 @@ def _attach_rom_folders(config: dict, platform_name: str, platforms_dir: str) ->
|
||||
config["_rom_folders"] = [row for row in folders if isinstance(row, dict)]
|
||||
|
||||
|
||||
def load_platform_config(platform_name: str, platforms_dir: str = "platforms") -> dict:
|
||||
def load_platform_config(platform_name: str, platforms_dir: str = PLATFORMS_DIR) -> dict:
|
||||
"""Load a platform config with inheritance and shared group resolution.
|
||||
|
||||
This is the SINGLE implementation used by generate_pack, generate_readme,
|
||||
|
||||
@@ -15,7 +15,7 @@ except ImportError:
|
||||
from core.cli import InputMissing, suggest_names
|
||||
from model.alternatives import derive_member_requirements
|
||||
from model.sources import source_yaml
|
||||
from model.systems import norm_system_id
|
||||
from model.systems import norm_system_id, system_index
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
@@ -52,6 +52,17 @@ def profiles_for_systems(
|
||||
return matching
|
||||
|
||||
|
||||
def no_profile_for_systems(profiles: dict, system_ids: list[str], standalone: bool = False) -> str:
|
||||
"""Why profiles_for_systems found nothing, with the closest system ids."""
|
||||
kind = "standalone emulators" if standalone else "emulators"
|
||||
all_systems = sorted({sid for p in profiles.values() for sid in p.get("systems", [])})
|
||||
# --list-systems merges spellings that differ in case or separator:
|
||||
# the hint counted 579 spellings for the 532 lines it prints.
|
||||
hint = suggest_names(system_ids, all_systems, "--list-systems",
|
||||
listed=len(system_index(profiles)))
|
||||
return f"No {kind} found for system(s): {', '.join(system_ids)}\n{hint}"
|
||||
|
||||
|
||||
def entry_system_ids(entry: dict, profile: dict) -> list[str]:
|
||||
"""Systems a profile entry serves.
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from model.registry import list_release_pack_platforms
|
||||
|
||||
|
||||
@@ -32,7 +33,7 @@ def get_page(platform: str, site: str = "") -> str:
|
||||
return f"{site}{GET_DIR}/{platform}/"
|
||||
|
||||
|
||||
def advertised(record: dict, platforms_dir: str = "platforms") -> dict:
|
||||
def advertised(record: dict, platforms_dir: str = PLATFORMS_DIR) -> dict:
|
||||
"""The record as the download tables show it: release_pack platforms only.
|
||||
|
||||
A release cut before a platform lost its release_pack still holds that
|
||||
@@ -51,7 +52,7 @@ def advertised(record: dict, platforms_dir: str = "platforms") -> dict:
|
||||
return {**record, "packs": packs}
|
||||
|
||||
|
||||
def load_advertised(path: str | Path = RECORD, platforms_dir: str = "platforms") -> dict:
|
||||
def load_advertised(path: str | Path = RECORD, platforms_dir: str = PLATFORMS_DIR) -> dict:
|
||||
"""The committed record, reduced to the platforms a release publishes."""
|
||||
return advertised(load_record(path), platforms_dir)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import re
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import EMULATORS_DIR, PLATFORMS_DIR
|
||||
from model.systems import norm_system_id
|
||||
from model.registry import list_registered_platforms
|
||||
from model.profiles import load_emulator_profiles, preferred_profile, upstream_profile_index
|
||||
@@ -97,7 +98,7 @@ class SystemResolver:
|
||||
|
||||
@classmethod
|
||||
def from_repo(
|
||||
cls, emulators_dir: str = "emulators", platforms_dir: str = "platforms"
|
||||
cls, emulators_dir: str = EMULATORS_DIR, platforms_dir: str = PLATFORMS_DIR
|
||||
) -> SystemResolver:
|
||||
profiles = load_emulator_profiles(emulators_dir)
|
||||
use: dict[str, int] = {}
|
||||
@@ -159,7 +160,7 @@ class ProfileResolver:
|
||||
index: dict[str, set[str]]
|
||||
|
||||
@classmethod
|
||||
def from_repo(cls, emulators_dir: str = "emulators") -> ProfileResolver:
|
||||
def from_repo(cls, emulators_dir: str = EMULATORS_DIR) -> ProfileResolver:
|
||||
return cls(upstream_profile_index(load_emulator_profiles(emulators_dir)))
|
||||
|
||||
def resolve(self, core: str | None) -> str | None:
|
||||
|
||||
@@ -4,8 +4,10 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from core.cli import SourceUnreadable, suggest_names
|
||||
from model.sources import source_yaml
|
||||
|
||||
@@ -29,7 +31,7 @@ def _target_alias_index(targets: dict, overrides: dict) -> dict[str, str]:
|
||||
return alias_index
|
||||
|
||||
|
||||
def platform_files_target(platform: str, target: str, platforms_dir: str = "platforms") -> bool:
|
||||
def platform_files_target(platform: str, target: str, platforms_dir: str = PLATFORMS_DIR) -> bool:
|
||||
"""Whether the platform's targets file knows this target, by any alias."""
|
||||
targets_dir = os.path.join(platforms_dir, "targets")
|
||||
target_file = os.path.join(targets_dir, f"{platform}.yml")
|
||||
@@ -41,7 +43,7 @@ def platform_files_target(platform: str, target: str, platforms_dir: str = "plat
|
||||
|
||||
|
||||
def canonical_target_name(
|
||||
platforms: list[str], target: str, platforms_dir: str = "platforms"
|
||||
platforms: list[str], target: str, platforms_dir: str = PLATFORMS_DIR
|
||||
) -> str:
|
||||
"""The name a target is filed under, whichever alias was typed.
|
||||
|
||||
@@ -66,7 +68,7 @@ def canonical_target_name(
|
||||
|
||||
|
||||
def truth_target_dir(
|
||||
output_dir: str, platforms: list[str], target: str, platforms_dir: str = "platforms"
|
||||
output_dir: str, platforms: list[str], target: str, platforms_dir: str = PLATFORMS_DIR
|
||||
) -> str:
|
||||
"""Where a target-narrowed truth model is written and read.
|
||||
|
||||
@@ -84,7 +86,7 @@ def truth_target_dir(
|
||||
def load_target_config(
|
||||
platform_name: str,
|
||||
target: str,
|
||||
platforms_dir: str = "platforms",
|
||||
platforms_dir: str = PLATFORMS_DIR,
|
||||
) -> set[str] | None:
|
||||
"""Load target config and return the set of core names for the given target.
|
||||
|
||||
@@ -169,7 +171,7 @@ def apply_target_overrides(
|
||||
|
||||
def list_available_targets(
|
||||
platform_name: str,
|
||||
platforms_dir: str = "platforms",
|
||||
platforms_dir: str = PLATFORMS_DIR,
|
||||
) -> list[dict]:
|
||||
"""List available targets for a platform with their aliases.
|
||||
|
||||
@@ -256,6 +258,23 @@ def build_target_cores_cache(
|
||||
return cache, kept
|
||||
|
||||
|
||||
def target_scope(
|
||||
platforms: list[str],
|
||||
target: str | None,
|
||||
platforms_dir: str,
|
||||
is_all: bool = False,
|
||||
) -> tuple[dict[str, set[str] | None], list[str]]:
|
||||
"""build_target_cores_cache for a command line: no target keeps every
|
||||
platform unfiltered, a refused target ends the run with its reason."""
|
||||
if not target:
|
||||
return {}, platforms
|
||||
try:
|
||||
return build_target_cores_cache(platforms, target, platforms_dir, is_all=is_all)
|
||||
except (FileNotFoundError, ValueError) as exc:
|
||||
print(f"ERROR: {exc}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _unknown_target_message(target: str, platforms: list[str], platforms_dir: str) -> str:
|
||||
"""A target no platform has, with the closest names any of them knows."""
|
||||
import difflib
|
||||
|
||||
Reference in new issue
Block a user