Coverage for github_test/pipeline.py: 100%
24 statements
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-06 18:26 +0000
« prev ^ index » next coverage.py v7.15.0, created at 2026-07-06 18:26 +0000
1"""An example module: a tiny text-transform pipeline.
3This is throwaway "replace-me" starter code. It exists to show how the project is
4wired together -- in particular how Hydra's ``instantiate`` builds a *nested* object
5graph from config: a ``Pipeline`` whose ``steps`` are themselves ``_target_`` objects
6(see ``configs/pipeline.yaml``). Delete it and drop in your own package code.
7"""
9from abc import ABC, abstractmethod
10from dataclasses import dataclass
12from loguru import logger
15class Transform(ABC):
16 """A single pipeline step that maps a string to a string."""
18 @abstractmethod
19 def __call__(self, text: str) -> str:
20 """Apply the transform to ``text`` and return the result."""
23class Upper(Transform):
24 """Upper-cases the text."""
26 def __call__(self, text: str) -> str:
27 """Return ``text`` upper-cased."""
28 return text.upper()
31class Repeat(Transform):
32 """Repeats the text ``times`` times, space-separated."""
34 def __init__(self, times: int = 2) -> None:
35 """Store how many times to repeat the text."""
36 self.times = times
38 def __call__(self, text: str) -> str:
39 """Return ``text`` repeated ``times`` times, space-separated."""
40 return " ".join([text] * self.times)
43@dataclass
44class Pipeline:
45 """Runs an ordered list of transforms over a starting message."""
47 steps: list[Transform]
48 message: str = "hello"
50 def run(self) -> str:
51 """Apply each transform in turn, log the result, and return it."""
52 result = self.message
53 for step in self.steps:
54 result = step(result)
55 logger.info(result)
56 return result