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

1"""Layout — the emit-phase layer of the ROM Farmer IR. 

2 

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. 

7 

8Emitters consume ``LayoutPlan`` as their sole input — they never ``rglob`` 

9the output tree (briefing §3.8). 

10""" 

11 

12from __future__ import annotations 

13 

14import enum 

15import types 

16from collections.abc import Mapping 

17from dataclasses import dataclass 

18from pathlib import Path 

19 

20from .catalog import UnitId 

21from .identity import Identity 

22 

23 

24class MetadataDialect(enum.Enum): 

25 NONE = "none" 

26 ES_GAMELIST = "es_gamelist" 

27 

28 

29@dataclass(frozen=True, slots=True) 

30class LayoutConstraints: 

31 """Filesystem constraints imposed by the target device / frontend.""" 

32 

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() 

37 

38 

39@dataclass(frozen=True, slots=True) 

40class MediaPolicy: 

41 """Media asset constraints for the target frontend.""" 

42 

43 max_image_width: int | None = None 

44 max_image_height: int | None = None 

45 allow_video: bool = True 

46 

47 

48@dataclass(frozen=True, slots=True) 

49class PlatformCapability: 

50 """How well the target device runs one platform (from config/devices).""" 

51 

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 = "" 

56 

57 

58@dataclass(frozen=True, slots=True) 

59class LayoutEntry: 

60 """One artifact's placement in the output tree.""" 

61 

62 artifact_sha256: str 

63 relative_path: Path 

64 

65 

66@dataclass(frozen=True, slots=True) 

67class LayoutPlan: 

68 """Complete placement map for one build's output tree. 

69 

70 This is the only input to emitters — they derive the full output structure 

71 from ``entries`` without scanning the filesystem. 

72 """ 

73 

74 root_name: str 

75 entries: tuple[LayoutEntry, ...] 

76 

77 

78@dataclass(frozen=True, slots=True) 

79class OutputSet: 

80 """Result of EXECUTE: resolved output identities keyed by unit. 

81 

82 ``unit_outputs`` is stored as an immutable ``MappingProxyType`` regardless 

83 of what the caller passes (same treatment as ``Action.params``). 

84 

85 ``budget_stopped`` lists the ``UnitId`` strings of units that were skipped 

86 because the executor hit the ``budget_bytes`` stop-early threshold. 

87 """ 

88 

89 unit_outputs: Mapping[UnitId, tuple[Identity, ...]] 

90 budget_stopped: tuple[str, ...] = () 

91 

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 )