Coverage for src/romfarmer/targets/emitters/base.py: 0%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-01 23:08 -0700

1"""TargetEmitter protocol and PostHook type. 

2 

3A ``TargetEmitter`` is the EMIT-phase counterpart to the PLAN-phase 

4planner passes: it takes a materialised ``OutputSet`` and produces the 

5final on-disk layout (organised files + metadata). 

6 

7Emitters are **pure** for ``plan_layout`` (returns data, no I/O) and 

8**side-effecting** for ``emit_metadata`` and ``post_process``. 

9""" 

10 

11from __future__ import annotations 

12 

13from dataclasses import dataclass 

14from pathlib import Path 

15from typing import TYPE_CHECKING, Protocol 

16 

17if TYPE_CHECKING: 

18 from romfarmer.analysis.knowledge import KnowledgeBase 

19 from romfarmer.ir.actions import ArtifactDecl 

20 from romfarmer.ir.layout import LayoutPlan 

21 from romfarmer.targets.profiles.loader import ConcreteTargetProfile 

22 

23 

24@dataclass(frozen=True) 

25class PostHook: 

26 """A post-EMIT command to run (e.g. jdupes, rsync).""" 

27 

28 name: str 

29 command: list[str] 

30 

31 

32class TargetEmitter(Protocol): 

33 """EMIT-phase behavior for a specific target type. 

34 

35 Implementations live in the sibling modules 

36 (generic.py, es_gamelist.py, extras.py). 

37 """ 

38 

39 def plan_layout( 

40 self, 

41 output_dir: Path, 

42 profile: ConcreteTargetProfile, 

43 ) -> LayoutPlan: 

44 """Return the desired output tree as pure data. No I/O.""" 

45 ... 

46 

47 def emit_metadata( 

48 self, 

49 layout: LayoutPlan, 

50 output_dir: Path, 

51 kb: KnowledgeBase, 

52 profile: ConcreteTargetProfile, 

53 ) -> list[ArtifactDecl]: 

54 """Generate metadata files (gamelist.xml, etc.). Side-effecting.""" 

55 ... 

56 

57 def post_process(self, root: Path) -> list[PostHook]: 

58 """Return post-process hooks to run after all files are placed.""" 

59 ...