mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
refactor: take narrowing options as typed keywords
This commit is contained in:
1 parent
def15d2a50
commit
bc50106587
3 files changed
+60
-12
No files matched your search
@@ -23,6 +23,7 @@ from collections import Counter
|
||||
import dataclasses
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
from alternatives import set_keys, set_requirements, settle_sets
|
||||
@@ -81,6 +82,9 @@ from validation import (
|
||||
with_archive_members,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Unpack
|
||||
|
||||
yaml = require_yaml()
|
||||
|
||||
DEFAULT_EMULATORS_DIR = "emulators"
|
||||
@@ -1455,18 +1459,24 @@ def print_launcher_reads(rows: list[dict]) -> None:
|
||||
)
|
||||
|
||||
|
||||
class ReportScope(TypedDict, total=False):
|
||||
"""What a cross_reference run compares against and answers for."""
|
||||
|
||||
all_declared: dict[str, list[tuple[int | None, str]]] | None
|
||||
standalone_cores: set[str] | None
|
||||
folded_slots: frozenset[str]
|
||||
platform: str
|
||||
launcher_layer: LauncherLayer | None
|
||||
declared_contents: dict[str, set[str]] | None
|
||||
|
||||
|
||||
def cross_reference(
|
||||
profiles: dict[str, dict],
|
||||
declared: dict[str, set[str]],
|
||||
db: dict,
|
||||
platform_data_dirs: dict[str, set[str]] | None = None,
|
||||
data_names: set[str] | None = None,
|
||||
all_declared: dict[str, list[tuple[int | None, str]]] | None = None,
|
||||
standalone_cores: set[str] | None = None,
|
||||
folded_slots: frozenset[str] = frozenset(),
|
||||
platform: str = "",
|
||||
launcher_layer: LauncherLayer | None = None,
|
||||
declared_contents: dict[str, set[str]] | None = None,
|
||||
**scope: Unpack[ReportScope],
|
||||
) -> dict:
|
||||
"""Compare emulator profiles against platform declarations.
|
||||
|
||||
@@ -1483,6 +1493,15 @@ def cross_reference(
|
||||
instead of the per-system lookup. This is appropriate for the global
|
||||
gap analysis page where "undeclared" means "no platform declares it at all".
|
||||
"""
|
||||
unknown = sorted(set(scope) - set(ReportScope.__annotations__))
|
||||
if unknown:
|
||||
raise TypeError(f"cross_reference() got an unexpected keyword argument '{unknown[0]}'")
|
||||
all_declared = scope.get("all_declared")
|
||||
standalone_cores = scope.get("standalone_cores")
|
||||
folded_slots = scope.get("folded_slots", frozenset())
|
||||
platform = scope.get("platform", "")
|
||||
launcher_layer = scope.get("launcher_layer")
|
||||
declared_contents = scope.get("declared_contents")
|
||||
platform_data_dirs = platform_data_dirs or {}
|
||||
by_name = db.get("indexes", {}).get("by_name", {})
|
||||
by_name_lower = {k.lower(): k for k in by_name}
|
||||
|
||||
+15
-1
@@ -11,6 +11,7 @@ import os
|
||||
import re
|
||||
import zipfile
|
||||
from collections.abc import Callable, Collection, Iterator, Mapping, Sequence
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
from common import (
|
||||
adler32_of,
|
||||
@@ -28,6 +29,9 @@ from hashing import md5_composite, parse_hash_list, parse_md5_list
|
||||
from nativemode import SIZE_AND_ANY_HASH, digest_algorithm, hash_mismatch_excludes_file
|
||||
from ziptools import check_inside_zip
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Unpack
|
||||
|
||||
# Validation types that require console-specific cryptographic keys.
|
||||
# verify.py cannot reproduce these: size checks still apply if combined.
|
||||
_CRYPTO_CHECKS = frozenset({"signature", "crypto"})
|
||||
@@ -1140,6 +1144,12 @@ def _owners_of(destination: str, name: str, owners: dict) -> set[str]:
|
||||
return {emu for tail, emu in matching if len(tail) == longest}
|
||||
|
||||
|
||||
class Judges(TypedDict, total=False):
|
||||
"""The cores that judge a file in validated_choice, each by its own entries."""
|
||||
|
||||
emulators: set[str] | None
|
||||
|
||||
|
||||
def validated_choice(
|
||||
file_entry: dict,
|
||||
local_path: str | None,
|
||||
@@ -1149,7 +1159,7 @@ def validated_choice(
|
||||
platform_digest: str | None,
|
||||
destination: str = "",
|
||||
owners: dict | None = None,
|
||||
emulators: set[str] | None = None,
|
||||
**judging: Unpack[Judges],
|
||||
) -> tuple[str | None, str | None]:
|
||||
"""The file a platform destination ships, and the disagreement if any.
|
||||
|
||||
@@ -1159,6 +1169,10 @@ def validated_choice(
|
||||
another emulator declares more precisely is that emulator's: ZEsarUX's
|
||||
48 KB cpc6128.rom check has no say over ep128emu/roms/cpc6128.rom.
|
||||
"""
|
||||
unknown = sorted(set(judging) - set(Judges.__annotations__))
|
||||
if unknown:
|
||||
raise TypeError(f"validated_choice() got an unexpected keyword argument '{unknown[0]}'")
|
||||
emulators = judging.get("emulators")
|
||||
if not local_path or not validation_index:
|
||||
return local_path, None
|
||||
name = file_entry.get("name", "")
|
||||
|
||||
+20
-5
@@ -33,7 +33,7 @@ from collections import Counter
|
||||
from collections.abc import Callable, Mapping
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
import slots
|
||||
|
||||
@@ -137,6 +137,8 @@ from validation import (
|
||||
from packpaths import core_save_folder
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import Unpack
|
||||
|
||||
from packextras import ExtraResolver
|
||||
|
||||
yaml = require_yaml()
|
||||
@@ -1788,6 +1790,15 @@ def _profile_coverage(
|
||||
return with_validation, with_profile
|
||||
|
||||
|
||||
class PlatformNarrowing(TypedDict, total=False):
|
||||
"""The narrowings of a platform pack verify_platform reports on."""
|
||||
|
||||
regions: list[str] | None
|
||||
system_filter: list[str] | None
|
||||
no_game_data: bool
|
||||
required_only: bool
|
||||
|
||||
|
||||
def verify_platform(
|
||||
config: dict,
|
||||
db: dict,
|
||||
@@ -1795,10 +1806,7 @@ def verify_platform(
|
||||
emu_profiles: dict | None = None,
|
||||
target_cores: set[str] | None = None,
|
||||
data_dir_registry: dict | None = None,
|
||||
regions: list[str] | None = None,
|
||||
system_filter: list[str] | None = None,
|
||||
no_game_data: bool = False,
|
||||
required_only: bool = False,
|
||||
**narrowing: Unpack[PlatformNarrowing],
|
||||
) -> dict:
|
||||
"""Verify all BIOS files for a platform, including cross-reference gaps.
|
||||
|
||||
@@ -1813,6 +1821,13 @@ def verify_platform(
|
||||
declarations, trees and core extras marked ``required: false`` are left
|
||||
out before any of them takes a path, as the builder leaves them out.
|
||||
"""
|
||||
unknown = sorted(set(narrowing) - set(PlatformNarrowing.__annotations__))
|
||||
if unknown:
|
||||
raise TypeError(f"verify_platform() got an unexpected keyword argument '{unknown[0]}'")
|
||||
regions = narrowing.get("regions")
|
||||
system_filter = narrowing.get("system_filter")
|
||||
no_game_data = narrowing.get("no_game_data", False)
|
||||
required_only = narrowing.get("required_only", False)
|
||||
left_out: list[str] = []
|
||||
if no_game_data:
|
||||
config, emu_profiles, left_out = _cut_game_data(
|
||||
|
||||
Reference in new issue
Block a user