Add orchestrator and Echo module

This commit is contained in:
Joscha 2025-08-29 22:42:51 +02:00
parent dc37d13866
commit a6998456df
5 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,11 @@
from . import modules
from .cmd import run_capture, run_check
from .orchestrator import Module, Orchestrator
__all__: list[str] = [
"Module",
"Orchestrator",
"modules",
"run_capture",
"run_check",
]

View file

@ -0,0 +1,5 @@
from .echo import Echo
__all__: list[str] = [
"Echo",
]

14
pasch/modules/echo.py Normal file
View file

@ -0,0 +1,14 @@
from pasch.cmd import run_check
from pasch.orchestrator import Module, Orchestrator
class Echo(Module):
def __init__(self, orchestrator: Orchestrator) -> None:
super().__init__(orchestrator)
self.args: list[str] = []
def add(self, arg: str) -> None:
self.args.append(arg)
def realize(self) -> None:
run_check("echo", *self.args)

28
pasch/orchestrator.py Normal file
View file

@ -0,0 +1,28 @@
from __future__ import annotations
from abc import ABC, abstractmethod
class Module(ABC):
def __init__(self, orchestrator: Orchestrator) -> None:
self.orchestrator = orchestrator
self.orchestrator.register(self)
@abstractmethod
def realize(self) -> None: ...
class Orchestrator:
def __init__(self) -> None:
self.frozen: bool = False
self.modules: list[Module] = []
def register(self, module: Module) -> None:
if self.frozen:
raise Exception("registering module wile orchestrator is frozen")
self.modules.append(module)
def realize(self) -> None:
self.frozen = True
for module in reversed(self.modules):
module.realize()

3
scripts/check Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env bash
uvx ruff check
uvx pyrefly check