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:
Abdessamad Derraz committed 2026-11-20 18:28:46 +01:00
1 parent 348d5b51c3
commit cf03dcb2ef
50 files changed
+260 -405

No files matched your search

+5 -7
View File
@@ -6,7 +6,7 @@ import os
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, TypedDict
from core.paths import declared_destination
from core.paths import BIOS_DIR, EMULATORS_DIR, declared_destination
from core.ziptools import build_zip_contents_index
from model.alternatives import core_file_spares
from model.declarations import OUTER_ROOTS, platform_declarations
@@ -16,8 +16,6 @@ from packs import slots
from packs.crossref import launcher_reads_not_held
from packs.gaps import find_exclusion_notes, find_undeclared_files
from packs.verdicts import (
DEFAULT_BIOS_DIR,
DEFAULT_EMULATORS_DIR,
RELEASE_ASSET_PENDING,
Severity,
Status,
@@ -198,7 +196,7 @@ def _twin_index(
from resolve.packfiles import preferred_entries as _preferred_entries
preferred_entries = _preferred_entries(
verify_systems, db, DEFAULT_BIOS_DIR, base_dest, False,
verify_systems, db, BIOS_DIR, base_dest, False,
zip_contents, True,
)
winners = {
@@ -306,7 +304,7 @@ def _resolve_for_platform(
declared_destination(file_entry)
)
local_path, status = resolve_declaration(
file_entry, db, DEFAULT_BIOS_DIR, zip_contents, data_dir_registry,
file_entry, db, BIOS_DIR, zip_contents, data_dir_registry,
override, offline=True,
)
if status in ("not_found", "hash_mismatch") and not run_is_offline():
@@ -690,7 +688,7 @@ def _platform_gaps(
run.emulators_dir, run.db, run.emu_profiles, run.target_cores, region_drops,
report_for_builder,
ExtraResolver(
run.db, DEFAULT_BIOS_DIR, run.zip_contents, run.data_dir_registry,
run.db, BIOS_DIR, run.zip_contents, run.data_dir_registry,
validation_index, validation_owners, profiles=run.profiles,
pending_assets=True,
),
@@ -741,7 +739,7 @@ class PlatformNarrowing(TypedDict, total=False):
def verify_platform(
config: dict,
db: dict,
emulators_dir: str = DEFAULT_EMULATORS_DIR,
emulators_dir: str = EMULATORS_DIR,
emu_profiles: dict | None = None,
target_cores: set[str] | None = None,
data_dir_registry: dict | None = None,
+6 -25
View File
@@ -7,22 +7,20 @@ import sys
from collections.abc import Callable
from dataclasses import dataclass, field
from core.cli import suggest_names
from core.hashing import compute_hashes
from core.paths import REPO_ROOT
from core.paths import BIOS_DIR, REPO_ROOT
from core.ziptools import build_zip_contents_index
from model.alternatives import set_requirements, settle_sets, slot_set_keys
from model.profiles import (
ProfileSelectionError,
entry_serves_systems,
load_emulator_profiles,
no_profile_for_systems,
profiles_for_systems,
select_emulator_profiles,
)
from model.registry import load_data_dir_registry
from model.systems import system_index
from packs.verdicts import (
DEFAULT_BIOS_DIR,
RELEASE_ASSET_PENDING,
Severity,
Status,
@@ -353,7 +351,7 @@ class _EmulatorPack:
local_path, resolve_status = self.pending(own_entry, *resolve_file(
own_entry,
self.db,
DEFAULT_BIOS_DIR,
BIOS_DIR,
self.zip_contents,
data_dir_registry=self.data_registry,
offline=True,
@@ -406,7 +404,7 @@ class _EmulatorPack:
local_path, resolve_status = self.pending(file_entry, *resolve_file(
{**with_archive_members(file_entry, files), "source_profile": emu_name},
self.db,
DEFAULT_BIOS_DIR,
BIOS_DIR,
self.zip_contents,
dest_hint=dest_hint,
data_dir_registry=self.data_registry,
@@ -464,7 +462,7 @@ class _EmulatorPack:
# Judged by this emulator's own entries, as it runs its check,
# through the selection the emulator pack makes.
chosen, disagreement = validated_choice(
file_entry, local_path, self.db, self.validation_index, DEFAULT_BIOS_DIR,
file_entry, local_path, self.db, self.validation_index, BIOS_DIR,
None, emulators={emu_name},
)
if disagreement:
@@ -739,24 +737,7 @@ def verify_system(
matching = profiles_for_systems(profiles, system_ids, standalone)
if not matching:
all_systems: set[str] = set()
for p in profiles.values():
all_systems.update(p.get("systems", []))
if standalone:
print(
f"No standalone emulators found for system(s): {', '.join(system_ids)}",
file=sys.stderr,
)
else:
print(
f"No emulators found for system(s): {', '.join(system_ids)}",
file=sys.stderr,
)
# --list-systems merges spellings that differ in case or separator:
# the hint counted 579 spellings for the 532 lines it prints.
print(suggest_names(system_ids, sorted(all_systems), "--list-systems",
listed=len(system_index(profiles))),
file=sys.stderr)
print(no_profile_for_systems(profiles, system_ids, standalone), file=sys.stderr)
sys.exit(1)
return verify_emulator(
+3 -20
View File
@@ -13,7 +13,6 @@ from collections.abc import Callable
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, TypedDict
from core.cli import suggest_names
from core.options import reject_unknown
from core.paths import REPO_ROOT
from core.ziptools import build_zip_contents_index
@@ -22,11 +21,12 @@ from model.profiles import (
ProfileSelectionError,
entry_serves_systems,
load_emulator_profiles,
no_profile_for_systems,
profiles_for_systems,
select_emulator_profiles,
)
from model.registry import load_data_dir_registry
from model.systems import MANUFACTURER_PREFIXES, system_index
from model.systems import MANUFACTURER_PREFIXES
from packs.archive import (
PackRecord,
Placed,
@@ -567,24 +567,7 @@ def generate_system_pack(
matching = profiles_for_systems(profiles, system_ids, standalone)
if not matching:
all_systems: set[str] = set()
for p in profiles.values():
all_systems.update(p.get("systems", []))
if standalone:
print(
f"No standalone emulators found for system(s): {', '.join(system_ids)}",
file=sys.stderr,
)
else:
print(
f"No emulators found for system(s): {', '.join(system_ids)}",
file=sys.stderr,
)
# --list-systems merges spellings that differ in case or separator:
# the hint counted 579 spellings for the 532 lines it prints.
print(suggest_names(system_ids, sorted(all_systems), "--list-systems",
listed=len(system_index(profiles))),
file=sys.stderr)
print(no_profile_for_systems(profiles, system_ids, standalone), file=sys.stderr)
return None
# Named like the platform's --system tag: one spelling of a system is
+3 -2
View File
@@ -13,6 +13,7 @@ from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, TypedDict
from core.paths import EMULATORS_DIR, PLATFORMS_DIR
from core.artifacts import set_plain_mode
from core.options import reject_unknown
from model.registry import list_registered_platforms
@@ -111,12 +112,12 @@ class FinalizeOptions(TypedDict, total=False):
class _FinalizeSettings:
"""FinalizeOptions with their defaults."""
platforms_dir: str = "platforms"
platforms_dir: str = PLATFORMS_DIR
skip_conformance: bool = False
data_registry: dict | None = None
regions: list[str] | None = None
target_name: str | None = None
emulators_dir: str = "emulators"
emulators_dir: str = EMULATORS_DIR
no_game_data: bool = False
pack_systems_by_name: dict[str, dict] | None = None
built: Iterable[str] | None = None
+2 -2
View File
@@ -11,7 +11,7 @@ from typing import TYPE_CHECKING, TypedDict
from core.artifacts import build_timestamp
from core.options import reject_unknown
from core.paths import REPO_ROOT, declared_destination, sanitize_pack_path
from core.paths import EMULATORS_DIR, REPO_ROOT, declared_destination, sanitize_pack_path
from model.declarations import OUTER_ROOTS, declared_root, outer_layout
from model.platforms import load_platform_config
from model.profiles import load_emulator_profiles
@@ -109,7 +109,7 @@ class ManifestOptions(InstallListOptions, total=False):
class _ManifestSettings:
"""ManifestOptions with their defaults."""
emulators_dir: str = "emulators"
emulators_dir: str = EMULATORS_DIR
zip_contents: dict | None = None
emu_profiles: dict | None = None
target_cores: set[str] | None = None
+4 -9
View File
@@ -9,17 +9,16 @@ import tempfile
import zipfile
from collections.abc import Callable, Iterable
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, TypedDict
from model.registry import load_platform_registry
from core.hashing import compute_hashes
from core.options import reject_unknown
from core.paths import sanitize_pack_path
from core.paths import EMULATORS_DIR, sanitize_pack_path
from model.alternatives import core_file_spares
from model.declarations import OUTER_ROOTS, declared_root
from model.platforms import load_platform_config
from model.profiles import load_emulator_profiles
from model.safeparse import yaml_load
from packs import slots
from packs.archive import (
CASE_FOLDING_OS,
@@ -313,7 +312,7 @@ class PackOptions(PackNarrowing, _PartScope, total=False):
class _PackSettings:
"""PackOptions with their defaults."""
emulators_dir: str = "emulators"
emulators_dir: str = EMULATORS_DIR
zip_contents: dict | None = None
data_registry: dict | None = None
emu_profiles: dict | None = None
@@ -1062,11 +1061,7 @@ class _PlatformPackBuild:
def _platform_registry(platforms_dir: str) -> dict:
"""The platforms of _registry.yml, or nothing when the file is absent."""
registry_path = Path(platforms_dir) / "_registry.yml"
if not registry_path.exists():
return {}
with open(registry_path) as f:
return (yaml_load(f) or {}).get("platforms", {})
return load_platform_registry(platforms_dir)
def generate_pack(
-6
View File
@@ -13,12 +13,6 @@ from resolve.validation import (
)
DEFAULT_BIOS_DIR = "bios"
DEFAULT_EMULATORS_DIR = "emulators"
# Status model: aligned with Batocera BiosStatus (batocera-systems:967-969)