fix: name uncached trees once per manifest

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 21:46:27 +01:00
1 parent 11e3ebb44f
commit bbb139bbaf
4 files changed
+44 -20

No files matched your search

+9 -15
View File
@@ -2,8 +2,6 @@
from __future__ import annotations from __future__ import annotations
import contextlib
import io
import os import os
from collections.abc import Callable, Iterator from collections.abc import Callable, Iterator
from dataclasses import dataclass, field from dataclasses import dataclass, field
@@ -26,7 +24,6 @@ from packs.datatrees import (
core_data_trees, core_data_trees,
pack_markers, pack_markers,
tree_readers, tree_readers,
uncached_warning,
) )
from packs.extras import ( from packs.extras import (
collect_emulator_extras, collect_emulator_extras,
@@ -96,7 +93,7 @@ class InstallListOptions(TypedDict, total=False):
fold_case: bool | None fold_case: bool | None
no_game_data: bool no_game_data: bool
one_per_slot: bool one_per_slot: bool
uncached_out: set[str] | None uncached_out: dict[str, str] | None
class ManifestOptions(InstallListOptions, total=False): class ManifestOptions(InstallListOptions, total=False):
@@ -125,7 +122,7 @@ class _ManifestSettings:
one_per_slot: bool = False one_per_slot: bool = False
known_slot_choices: dict | None = None known_slot_choices: dict | None = None
build_out: dict | None = None build_out: dict | None = None
uncached_out: set[str] | None = None uncached_out: dict[str, str] | None = None
@dataclass @dataclass
@@ -479,10 +476,8 @@ class _ManifestBuild:
core_trees=core_trees, core_trees=core_trees,
reclaim=reclaim, uncached_out=uncached, reclaim=reclaim, uncached_out=uncached,
)) ))
for ref_key, local_path in uncached:
print(uncached_warning(ref_key, local_path))
if opts.uncached_out is not None: if opts.uncached_out is not None:
opts.uncached_out.update(ref_key for ref_key, _path in uncached) opts.uncached_out.update(uncached)
# A platform entry found in a tree the pack carries is that tree's member: # A platform entry found in a tree the pack carries is that tree's member:
# the installer rebuilds it from the tree's archive. One found in a tree # the installer rebuilds it from the tree's archive. One found in a tree
# the pack does not carry stays omitted, held by the pack alone. # the pack does not carry stays omitted, held by the pack alone.
@@ -713,8 +708,8 @@ def generate_manifest(
One build: generate_install_list adds what --source truth and One build: generate_install_list adds what --source truth and
--standalone read. `build_out` receives the slot choices and the --standalone read. `build_out` receives the slot choices and the
profiles this build read, which that second build takes over. profiles this build read, which that second build takes over.
`uncached_out` receives the data directories the list carries and the `uncached_out` maps each data directory the list carries and the cache
cache does not hold. does not hold to its cache folder: the caller reports it.
""" """
reject_unknown("generate_manifest", options, ManifestOptions.__optional_keys__) reject_unknown("generate_manifest", options, ManifestOptions.__optional_keys__)
opts = _ManifestSettings(**options) opts = _ManifestSettings(**options)
@@ -822,11 +817,10 @@ def generate_install_list(
or settings.fold_case is not None or settings.one_per_slot): or settings.fold_case is not None or settings.one_per_slot):
return result return result
truth_options: InstallListOptions = {**options, "source": "truth"} truth_options: InstallListOptions = {**options, "source": "truth"}
with contextlib.redirect_stdout(io.StringIO()): truth = generate_manifest(
truth = generate_manifest( platform_name, platforms_dir, db, bios_dir, registry_path,
platform_name, platforms_dir, db, bios_dir, registry_path, **truth_options, known_slot_choices=built["slot_choices"],
**truth_options, known_slot_choices=built["slot_choices"], )
)
_mark_truth(result, truth) _mark_truth(result, truth)
layouts = standalone_layouts( layouts = standalone_layouts(
built["profiles"], settings.emulators_dir, db, bios_dir, built["profiles"], settings.emulators_dir, db, bios_dir,
+13 -1
View File
@@ -11,6 +11,7 @@ from core.artifacts import write_if_changed
from model.platforms import load_platform_config from model.platforms import load_platform_config
from model.registry import load_platform_registry from model.registry import load_platform_registry
from model.safeparse import require_yaml from model.safeparse import require_yaml
from packs.datatrees import uncached_warning
from packs.manifest import generate_install_list from packs.manifest import generate_install_list
from packs.naming import pack_narrowings, platform_target from packs.naming import pack_narrowings, platform_target
from packs.scope import platform_list_version from packs.scope import platform_list_version
@@ -60,6 +61,15 @@ def _alias_manifest(
return alias_manifest return alias_manifest
def report_uncached(uncached: dict[str, str], recorded: set[str] | None) -> None:
"""Name each data directory a list carries and the cache does not hold,
once, and record it for the run's exit code."""
for ref_key, local_path in uncached.items():
print(uncached_warning(ref_key, local_path))
if recorded is not None:
recorded.update(uncached)
def run_manifest_mode( def run_manifest_mode(
args: argparse.Namespace, args: argparse.Namespace,
groups: list[tuple[list[str], str]], groups: list[tuple[list[str], str]],
@@ -82,6 +92,7 @@ def run_manifest_mode(
if skip_empty_truth(args, source, representative, emu_profiles, tc, failed): if skip_empty_truth(args, source, representative, emu_profiles, tc, failed):
continue continue
layouts: dict = {} layouts: dict = {}
uncached: dict[str, str] = {}
try: try:
manifest = generate_install_list( manifest = generate_install_list(
representative, representative,
@@ -102,8 +113,9 @@ def run_manifest_mode(
required_only=required_only, required_only=required_only,
no_game_data=getattr(args, "no_game_data", False), no_game_data=getattr(args, "no_game_data", False),
standalone_out=layouts, standalone_out=layouts,
uncached_out=getattr(args, "uncached_trees", None), uncached_out=uncached,
) )
report_uncached(uncached, getattr(args, "uncached_trees", None))
narrow_suffix = "".join( narrow_suffix = "".join(
tag.lower() tag.lower()
for tag, _label in pack_narrowings( for tag, _label in pack_narrowings(
+6 -1
View File
@@ -165,6 +165,8 @@ def run_platform_packs(
# systems: the pack records them, so a pack alone (a # systems: the pack records them, so a pack alone (a
# handheld without Wi-Fi) can be narrowed by system. # handheld without Wi-Fi) can be narrowed by system.
board_list = Path(args.platforms_dir) / "targets" / f"{representative}.yml" board_list = Path(args.platforms_dir) / "targets" / f"{representative}.yml"
# The pack above named its uncached trees: these are recorded only.
unnamed: dict[str, str] = {}
systems_for[os.path.basename(zip_path)] = pack_systems(generate_manifest( systems_for[os.path.basename(zip_path)] = pack_systems(generate_manifest(
representative, args.platforms_dir, db, args.bios_dir, representative, args.platforms_dir, db, args.bios_dir,
registry_path, emulators_dir=args.emulators_dir, registry_path, emulators_dir=args.emulators_dir,
@@ -174,8 +176,11 @@ def run_platform_packs(
offline=args.offline, required_only=required_only, offline=args.offline, required_only=required_only,
data_registry=data_registry, data_registry=data_registry,
no_game_data=getattr(args, "no_game_data", False), no_game_data=getattr(args, "no_game_data", False),
uncached_out=getattr(args, "uncached_trees", None), uncached_out=unnamed,
), target_list(board_list) if board_list.is_file() else None) ), target_list(board_list) if board_list.is_file() else None)
recorded_trees: set[str] | None = getattr(args, "uncached_trees", None)
if recorded_trees is not None:
recorded_trees.update(unnamed)
if record_counts: if record_counts:
write_pack_counts(record_counts, recorded) write_pack_counts(record_counts, recorded)
+16 -3
View File
@@ -189,7 +189,7 @@ class AMissingDataDirectoryFailsTheRun(unittest.TestCase):
from packs.manifest import generate_manifest from packs.manifest import generate_manifest
root, db, registry = self._platform() root, db, registry = self._platform()
uncached: set[str] = set() uncached: dict[str, str] = {}
out = io.StringIO() out = io.StringIO()
with redirect_stdout(out): with redirect_stdout(out):
generate_manifest( generate_manifest(
@@ -198,8 +198,21 @@ class AMissingDataDirectoryFailsTheRun(unittest.TestCase):
emulators_dir=str(root / "emulators"), emulators_dir=str(root / "emulators"),
data_registry=registry, offline=True, uncached_out=uncached, data_registry=registry, offline=True, uncached_out=uncached,
) )
self.assertEqual(uncached, {"assets"}) # The library records; the run names each tree once.
self.assertIn("WARNING: data directory 'assets' not cached", out.getvalue()) self.assertEqual((uncached, out.getvalue()), ({"assets": str(root / "absent")}, ""))
def test_the_manifest_run_names_each_tree_once(self):
from packs.manifestrun import report_uncached
recorded: set[str] = set()
out = io.StringIO()
with redirect_stdout(out):
report_uncached({"assets": "/c/absent"}, recorded)
self.assertEqual(recorded, {"assets"})
self.assertEqual(out.getvalue(), (
" WARNING: data directory 'assets' not cached at /c/absent"
" (run refresh_data_dirs.py)\n"
))
def test_the_shared_walk_prints_nothing_and_keeps_no_state(self): def test_the_shared_walk_prints_nothing_and_keeps_no_state(self):
from packs import datatrees from packs import datatrees