refactor: one reader of a declared destination

This commit is contained in:
Abdessamad Derraz committed 2026-11-18 13:47:56 +01:00
1 parent d55555f3e0
commit 825c527d11
8 files changed
+30 -33

No files matched your search

+7
View File
@@ -18,3 +18,10 @@ def sanitize_pack_path(raw: str) -> str:
"""
raw = raw.replace("\\", "/")
return "/".join(p for p in raw.split("/") if p and p not in ("..", "."))
def declared_destination(entry: dict) -> str:
"""The destination a declaration names, its name when it names none,
normalized as sanitize_pack_path does: the key the builder, the manifest
and verify all file a declaration under."""
return sanitize_pack_path(entry.get("destination", entry.get("name", "")))
+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 sanitize_pack_path
from core.paths import 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
@@ -185,7 +185,7 @@ def _builder_placement(
def _dest_key(file_entry: dict, sys_id: str) -> str:
"""The path a declaration occupies, as the builder keys its pack."""
dest = sanitize_pack_path(file_entry.get("destination", file_entry.get("name", "")))
dest = declared_destination(file_entry)
return dest or f"{sys_id}/{file_entry.get('name', '')}"
@@ -236,7 +236,7 @@ def _resolve_declaration(
declaration's, which is hashed against the shipped file.
"""
base_dest = resolver.base_dest
bare = sanitize_pack_path(file_entry.get("destination", file_entry.get("name", "")))
bare = declared_destination(file_entry)
preferred = resolver.preferred_entries.get(f"{base_dest}/{bare}" if base_dest else bare)
held_by, winner = (None, file_entry)
if preferred is not None and preferred != id(file_entry):
@@ -303,7 +303,7 @@ def _resolve_for_platform(
from resolve.packfiles import pending_release_asset, resolve_declaration, run_is_offline
override = slot_overrides.get(
sanitize_pack_path(file_entry.get("destination", file_entry.get("name", "")))
declared_destination(file_entry)
)
local_path, status = resolve_declaration(
file_entry, db, DEFAULT_BIOS_DIR, zip_contents, data_dir_registry,
@@ -371,9 +371,7 @@ class _PlatformTally:
def judge(self, sys_id: str, file_entry: dict) -> None:
"""Verify one declaration and add it to its destination's tally."""
destination = sanitize_pack_path(
file_entry.get("destination", file_entry.get("name", ""))
)
destination = declared_destination(file_entry)
if self.region_drops and destination in self.region_drops:
return
local_path, resolve_status, held_by = _resolve_declaration(
+7 -9
View File
@@ -24,7 +24,7 @@ from resolve.layout import core_system_dirs, system_dir_path
from resolve.standalone import platform_layouts
from resolve.standalone import standalone_set as platform_standalone_set
from model.declarations import OUTER_ROOTS, outer_layout
from core.paths import sanitize_pack_path
from core.paths import declared_destination, sanitize_pack_path
from resolve.content import declares_shape, shape_fits, size_fits
from resolve.validation import deliverable, read_from_save_dir, read_from_system_dir
from packs.paths import libretro_systems, save_destination, save_layout
@@ -56,13 +56,13 @@ def extra_full_destination(fe: dict, prefix: str) -> str:
if fe.get("unprefixed"):
# A path of the install tree outside the BIOS folder (AmberELEC's
# pico-8/ beside bios/): no platform prefix in front.
return sanitize_pack_path(fe.get("destination", fe.get("name", "")))
return declared_destination(fe)
if fe.get("root") in OUTER_ROOTS:
return outer_destination(
fe["root"], sanitize_pack_path(fe.get("destination", fe.get("name", "")))
fe["root"], declared_destination(fe)
)
return prefixed_destination(
sanitize_pack_path(fe.get("destination", fe.get("name", ""))), prefix
declared_destination(fe), prefix
)
@@ -100,7 +100,7 @@ def extra_region_key(fe: dict, prefix: str) -> str:
and the installer, which records the path once, dropped it.
"""
return prefixed_destination(
sanitize_pack_path(fe.get("destination", fe.get("name", ""))), prefix
declared_destination(fe), prefix
)
@@ -487,7 +487,7 @@ def hidden_extras(
def _packable_dest(fe: dict, region_drops: set[str] | None, region_prefix: str) -> str:
"""The extra's destination, empty when the builder never places it."""
dest = sanitize_pack_path(fe.get("destination", fe.get("name", "")))
dest = declared_destination(fe)
if not dest or (region_drops and extra_region_key(fe, region_prefix) in region_drops):
return ""
if fe.get("root") in OUTER_ROOTS:
@@ -2188,9 +2188,7 @@ def platform_region_groups(
# Decided over what the pack keeps: an optional winner removed
# afterwards left its slot empty.
for file_entry in _kept(system.get("files", []), required_only):
dest = sanitize_pack_path(
file_entry.get("destination", file_entry.get("name", ""))
)
dest = declared_destination(file_entry)
if dest:
members.append((dest, file_entry.get("name", "")))
full_dest = f"{base_dest}/{dest}" if base_dest else dest
+2 -2
View File
@@ -38,7 +38,7 @@ from resolve.packfiles import resolve_declaration, resolve_file
from resolve.categories import BIOS, EntryCategories
from resolve.gamedata import without_game_data
from resolve.cores import resolve_platform_cores
from core.paths import sanitize_pack_path
from core.paths import declared_destination
import zipfile
from collections.abc import Callable
@@ -841,7 +841,7 @@ def _baseline_groups(
system_of[id(fe)] = sys_id
if opts.required_only and fe.get("required") is False:
continue
dest = sanitize_pack_path(fe.get("destination", fe.get("name", "")))
dest = declared_destination(fe)
if not dest:
continue
if expect.region_drops and dest in expect.region_drops:
+3 -3
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, sanitize_pack_path
from core.paths import 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
@@ -209,7 +209,7 @@ class _ManifestBuild:
) -> None:
# A core extra (cores given) is keyed as the region pass keys it.
bare = (
sanitize_pack_path(file_entry.get("destination", file_entry.get("name", "")))
declared_destination(file_entry)
if cores is None else extra_region_key(file_entry, declared_root(self.config))
)
self.omitted_by_destination[full_destination] = {
@@ -648,7 +648,7 @@ def _settle_manifest_scope(build: _ManifestBuild) -> None:
declared_kinds: dict[str, set[bool]] = {}
for system in build.pack_systems.values():
for fe in system.get("files", []):
bare = sanitize_pack_path(fe.get("destination", fe.get("name", "")))
bare = declared_destination(fe)
if bare:
declared_kinds.setdefault(bare, set()).add(id(fe) in build.game_entries)
build.game_destinations = {d for d, kinds in declared_kinds.items() if kinds == {True}}
+2 -2
View File
@@ -8,7 +8,7 @@ from collections.abc import Callable
from dataclasses import dataclass
from core.hashing import compute_hashes
from core.paths import sanitize_pack_path
from core.paths import declared_destination
from model.declarations import OUTER_ROOTS, declared_root
from model.largefiles import asset_name, load_registered_paths, published_asset_name
from packs.extras import (
@@ -396,7 +396,7 @@ def _record_absent(
for fe in absent:
if required_only and fe.get("required") is False:
continue
dest = sanitize_pack_path(fe.get("destination", fe.get("name", "")))
dest = declared_destination(fe)
if not dest or (
region_drops and extra_region_key(fe, declared_root(config)) in region_drops
):
+2 -6
View File
@@ -20,7 +20,7 @@ from dataclasses import dataclass
from resolve import regions as resolve_regions
from resolve import slot as slot_mod
from model.systems import _norm_system_id
from core.paths import sanitize_pack_path
from core.paths import declared_destination
from packs.extras import (
_kept,
_serving_system_ids,
@@ -30,10 +30,6 @@ from packs.extras import (
)
def _dest(entry: dict) -> str:
return sanitize_pack_path(entry.get("destination", entry.get("name", "")))
@dataclass(frozen=True)
class SelectionIndex:
"""System and region facts for one platform, as the pack builder reads them."""
@@ -63,7 +59,7 @@ class SelectionIndex:
declared_by: dict[str, set[str]] = {}
for sys_id, system in pack_systems.items():
for file_entry in _kept(system.get("files", []), required_only):
dest = _dest(file_entry)
dest = declared_destination(file_entry)
if dest:
declared_by.setdefault(dest, set()).add(sys_id)
+2 -4
View File
@@ -17,7 +17,7 @@ from model.largefiles import fetch_large_file
from core.hashing import cut_md5_owner
from resolve.content import declared_hash_verdict
from resolve.localfile import resolution_is_hash_exact, resolve_local_file
from core.paths import REPO_ROOT, sanitize_pack_path
from core.paths import REPO_ROOT, declared_destination
from resolve.validation import inner_rom_check
# CLI-wide network policy. Public helpers can override it explicitly, while
# every CLI mode inherits --offline (including large-file release fallback).
@@ -457,9 +457,7 @@ def _declarations_by_destination(
for file_entry in system.get("files", []):
if required_only and file_entry.get("required") is False:
continue
dest = sanitize_pack_path(
file_entry.get("destination", file_entry.get("name", ""))
)
dest = declared_destination(file_entry)
if not dest:
continue
full = f"{base_dest}/{dest}" if base_dest else dest