Add orchestrator and Echo module
This commit is contained in:
parent
dc37d13866
commit
a6998456df
5 changed files with 61 additions and 0 deletions
|
|
@ -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",
|
||||||
|
]
|
||||||
5
pasch/modules/__init__.py
Normal file
5
pasch/modules/__init__.py
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
from .echo import Echo
|
||||||
|
|
||||||
|
__all__: list[str] = [
|
||||||
|
"Echo",
|
||||||
|
]
|
||||||
14
pasch/modules/echo.py
Normal file
14
pasch/modules/echo.py
Normal 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
28
pasch/orchestrator.py
Normal 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
3
scripts/check
Executable file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
uvx ruff check
|
||||||
|
uvx pyrefly check
|
||||||
Loading…
Add table
Add a link
Reference in a new issue