mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-22 17:47:48 -06:00
refactor: hand the native model its profiles
This commit is contained in:
1 parent
7baeb6475c
commit
19bcc76c8f
5 files changed
+34
-20
No files matched your search
@@ -13,6 +13,7 @@ from pathlib import Path
|
||||
import yaml
|
||||
|
||||
from core.artifacts import write_bytes_atomic, write_if_changed
|
||||
from core.paths import EMULATORS_DIR
|
||||
from core.text import count_text
|
||||
from core.ziptools import build_zip_contents_index
|
||||
from .base_exporter import BaseExporter
|
||||
@@ -60,12 +61,12 @@ def _truth_sources(platforms_dir: str) -> tuple[dict, dict, dict | None]:
|
||||
"""Registry, profiles and database, as generate_truth reads them."""
|
||||
registry = load_platform_registry(platforms_dir)
|
||||
db = load_database(TRUTH_DB) if Path(TRUTH_DB).exists() else None
|
||||
return registry, _profiles(), db
|
||||
return registry, export_profiles(), db
|
||||
|
||||
|
||||
def _profiles() -> dict[str, dict]:
|
||||
def export_profiles() -> dict[str, dict]:
|
||||
"""The emulator profiles the truth and the exporters read."""
|
||||
return load_emulator_profiles("emulators")
|
||||
return load_emulator_profiles(EMULATORS_DIR)
|
||||
|
||||
|
||||
def current_truth(platform: str, config: dict, platforms_dir: str) -> dict:
|
||||
@@ -118,8 +119,9 @@ def refresh_cache(
|
||||
truth, scraped = load_inputs(platform, truth_dir, platforms_dir)
|
||||
except StaleTruth as exc:
|
||||
return False, [str(exc)]
|
||||
systems, _ = build_native_model(truth or {}, scraped)
|
||||
exporter: BaseExporter = exporter_class(_profiles())
|
||||
profiles = export_profiles()
|
||||
systems, _ = build_native_model(truth or {}, scraped, profiles)
|
||||
exporter: BaseExporter = exporter_class(profiles)
|
||||
wanted = wanted_sources(exporter, systems, scraped)
|
||||
off_pin = unpinned(wanted, scraped)
|
||||
if off_pin:
|
||||
@@ -145,7 +147,7 @@ def doubled_in(scraped: dict | None, platforms_dir: str) -> list[dict]:
|
||||
return []
|
||||
db, zip_contents = _collection(TRUTH_DB)
|
||||
return doubled_destinations(
|
||||
scraped, _profiles(), db, zip_contents,
|
||||
scraped, export_profiles(), db, zip_contents,
|
||||
load_data_dir_registry(platforms_dir),
|
||||
)
|
||||
|
||||
@@ -223,14 +225,14 @@ def build_export(
|
||||
f"python scripts/generate_truth.py --platform {platform}"
|
||||
])
|
||||
|
||||
systems, report = build_native_model(truth, scraped)
|
||||
profiles = export_profiles()
|
||||
systems, report = build_native_model(truth, scraped, profiles)
|
||||
if not systems:
|
||||
return ExportResult(
|
||||
platform, False,
|
||||
["nothing to write: neither the platform nor the truth has data"],
|
||||
)
|
||||
|
||||
profiles = _profiles()
|
||||
exporter: BaseExporter = exporter_class(profiles)
|
||||
produced, issues, stopped = _produce(
|
||||
exporter, systems, report, scraped, upstream_dir, allow_fetch,
|
||||
|
||||
@@ -8,7 +8,7 @@ from collections.abc import Iterator
|
||||
from pathlib import Path
|
||||
|
||||
from exporter import discover_exporters
|
||||
from exporter.native import StaleTruth, build_export, load_inputs
|
||||
from exporter.native import StaleTruth, build_export, export_profiles, load_inputs
|
||||
from exporter.originals import SOURCES_INDEX, SourcesIndexUnreadable, load_sources, source_key, wanted_sources
|
||||
from model.platforms import inheritance_chain
|
||||
from model.registry import list_registered_platforms
|
||||
@@ -119,6 +119,7 @@ def check_native(
|
||||
except SourcesIndexUnreadable as exc:
|
||||
return [Finding("native", index.name, ERROR, detail=str(exc))]
|
||||
findings: list[Finding] = []
|
||||
profiles = export_profiles()
|
||||
for name in list_registered_platforms(str(platforms_dir)):
|
||||
exporter_class = exporters.get(name)
|
||||
if not exporter_class:
|
||||
@@ -129,7 +130,7 @@ def check_native(
|
||||
except StaleTruth as exc:
|
||||
findings.append(Finding("native", name, STALE, detail=str(exc)))
|
||||
continue
|
||||
systems, _ = build_native_model(truth or {}, scraped)
|
||||
systems, _ = build_native_model(truth or {}, scraped, profiles)
|
||||
wanted = wanted_sources(exporter_class(), systems, scraped)
|
||||
reason = native_cache_state(
|
||||
wanted, cache_dir / name, recorded, index, _transcribed_at(platforms_dir, name)
|
||||
|
||||
@@ -13,14 +13,15 @@ grouping is rebuilt from the per-file native_system the scrapers record.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
from collections.abc import Callable, Mapping
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from types import MappingProxyType
|
||||
|
||||
from core.hashing import HASH_FIELDS, declared_hashes, parse_hash_list
|
||||
from model.profiles import profile_names
|
||||
from model.systems import norm_system_id
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
_NO_PROFILES: Mapping[str, dict] = MappingProxyType({})
|
||||
|
||||
|
||||
def checked_hashes(entry: dict | None) -> dict | None:
|
||||
@@ -715,9 +716,12 @@ class _TruthPass:
|
||||
def build_native_model(
|
||||
truth: dict,
|
||||
scraped: dict | None,
|
||||
profiles: Mapping[str, dict] = _NO_PROFILES,
|
||||
) -> tuple[dict[str, NativeSystem], Report]:
|
||||
"""Rebuild the platform's systems, corrected by the truth.
|
||||
|
||||
`profiles` are the emulator profiles the truth was built from: they
|
||||
name the platform's runner of each addition, and none means no runner.
|
||||
Returns the systems keyed by native id, in the platform's own order
|
||||
first and truth-only additions after, plus what changed.
|
||||
"""
|
||||
@@ -740,11 +744,13 @@ def build_native_model(
|
||||
tail = [fe for fe in system.files if fe.platform is None]
|
||||
system.files = head + search_order(tail)
|
||||
|
||||
_attach_runners(systems, scraped)
|
||||
_attach_runners(systems, scraped, profiles)
|
||||
return systems, report
|
||||
|
||||
|
||||
def _attach_runners(systems: dict[str, NativeSystem], scraped: dict | None) -> None:
|
||||
def _attach_runners(
|
||||
systems: dict[str, NativeSystem], scraped: dict | None, profiles: Mapping[str, dict]
|
||||
) -> None:
|
||||
"""Name the cores behind each addition the way the platform names them.
|
||||
|
||||
The platform lists its cores by its own names (Batocera's
|
||||
@@ -756,7 +762,6 @@ def _attach_runners(systems: dict[str, NativeSystem], scraped: dict | None) -> N
|
||||
"""
|
||||
if not scraped:
|
||||
return
|
||||
from model.profiles import load_emulator_profiles
|
||||
from resolve.layout import runs_standalone
|
||||
from resolve.standalone import standalone_set
|
||||
|
||||
@@ -765,7 +770,6 @@ def _attach_runners(systems: dict[str, NativeSystem], scraped: dict | None) -> N
|
||||
standalone = {str(c) for c in scraped.get("standalone_cores") or []}
|
||||
# The build decision reads the tagged set (own builds, twins), as the
|
||||
# pack does. The runner's name is looked up among the plain names.
|
||||
profiles = load_emulator_profiles(str(REPO_ROOT / "emulators"))
|
||||
layout_set = standalone_set(scraped, profiles)
|
||||
for system in systems.values():
|
||||
for fe in system.files:
|
||||
|
||||
Reference in new issue
Block a user