Coverage for src/romfarmer/ir/layout.py: 98%
43 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-05 02:19 -0700
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-05 02:19 -0700
1"""Layout — the emit-phase layer of the ROM Farmer IR.
3``LayoutPlan`` replaces the ``organized_files_metadata`` shadow dict
4(briefing §3.6) with typed, per-artifact subdirectory placement.
5``OutputSet`` is the result of EXECUTE: a mapping from ``UnitId`` to the
6resolved ``Identity`` tuples for each unit's terminal artifacts.
8Emitters consume ``LayoutPlan`` as their sole input — they never ``rglob``
9the output tree (briefing §3.8).
10"""
12from __future__ import annotations
14import enum
15import types
16from collections.abc import Mapping
17from dataclasses import dataclass
18from pathlib import Path
20from .catalog import UnitId
21from .identity import Identity
24class MetadataDialect(enum.Enum):
25 NONE = "none"
26 ES_GAMELIST = "es_gamelist"
29@dataclass(frozen=True, slots=True)
30class LayoutConstraints:
31 """Filesystem constraints imposed by the target device / frontend."""
33 max_files_per_dir: int | None = None
34 max_depth: int | None = None
35 filename_max_len: int | None = None
36 forbidden_chars: frozenset[str] = frozenset()
39@dataclass(frozen=True, slots=True)
40class MediaPolicy:
41 """Media asset constraints for the target frontend."""
43 max_image_width: int | None = None
44 max_image_height: int | None = None
45 allow_video: bool = True
48@dataclass(frozen=True, slots=True)
49class PlatformCapability:
50 """How well the target device runs one platform (from config/devices)."""
52 tier: str # "A" | "B" | "C" | "X"
53 quality: float = 1.0
54 playable_list: str | None = None # curated ref, required for tier C
55 notes: str = ""
58@dataclass(frozen=True, slots=True)
59class LayoutEntry:
60 """One artifact's placement in the output tree."""
62 artifact_sha256: str
63 relative_path: Path
66@dataclass(frozen=True, slots=True)
67class LayoutPlan:
68 """Complete placement map for one build's output tree.
70 This is the only input to emitters — they derive the full output structure
71 from ``entries`` without scanning the filesystem.
72 """
74 root_name: str
75 entries: tuple[LayoutEntry, ...]
78@dataclass(frozen=True, slots=True)
79class OutputSet:
80 """Result of EXECUTE: resolved output identities keyed by unit.
82 ``unit_outputs`` is stored as an immutable ``MappingProxyType`` regardless
83 of what the caller passes (same treatment as ``Action.params``).
85 ``budget_stopped`` lists the ``UnitId`` strings of units that were skipped
86 because the executor hit the ``budget_bytes`` stop-early threshold.
87 """
89 unit_outputs: Mapping[UnitId, tuple[Identity, ...]]
90 budget_stopped: tuple[str, ...] = ()
92 def __post_init__(self) -> None:
93 if not isinstance(self.unit_outputs, types.MappingProxyType):
94 object.__setattr__(
95 self,
96 "unit_outputs",
97 types.MappingProxyType(dict(self.unit_outputs)),
98 )