From 38505cb004e4b09ba46f95a0e15e9f29eef614cd Mon Sep 17 00:00:00 2001 From: Josh Karpel Date: Mon, 24 Jun 2024 00:33:59 -0500 Subject: [PATCH] tweaks --- docs/changelog.md | 13 ++++++++----- synthesize/execution.py | 4 ++-- synthesize/messages.py | 12 +++++------- synthesize/renderer.py | 17 +++++------------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3e2d9dd..d70ee61 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,15 +2,18 @@ ## `0.0.3` -- [#30](https://github.com/JoshKarpel/synthesize/pull/30) - Reorganized configuration to separate targets, - triggers (formerly "lifecycles"), - and flows (graphs of targets and triggers)." +*Unreleased* ### Added - [#3](https://github.com/JoshKarpel/synthesize/pull/3) Added PyPI classifiers and other metadata. -- [#4](https://github.com/JoshKarpel/synthesize/pull/4) Switch to Parsy (from Lark) for parsing `synthfile`s and hit 100% coverage of the underlying format. + +### Changed + +- [#30](https://github.com/JoshKarpel/synthesize/pull/30) + Reorganized configuration to separate targets, + triggers (formerly "lifecycles"), + and flows (graphs of targets and triggers)." ## `0.0.2` diff --git a/synthesize/execution.py b/synthesize/execution.py index 7bd31c4..9512543 100644 --- a/synthesize/execution.py +++ b/synthesize/execution.py @@ -13,7 +13,7 @@ from stat import S_IEXEC from synthesize.config import FlowNode -from synthesize.messages import CommandMessage, ExecutionCompleted, ExecutionStarted, Message +from synthesize.messages import ExecutionCompleted, ExecutionOutput, ExecutionStarted, Message @lru_cache(maxsize=2**10) @@ -142,7 +142,7 @@ async def read_output(node: FlowNode, process: Process, events: Queue[Message]) break await events.put( - CommandMessage( + ExecutionOutput( node=node, text=line.decode("utf-8").rstrip(), ) diff --git a/synthesize/messages.py b/synthesize/messages.py index c818c49..5fddac6 100644 --- a/synthesize/messages.py +++ b/synthesize/messages.py @@ -11,20 +11,18 @@ class Message(Model): timestamp: datetime = Field(default_factory=datetime.now) -class CommandLifecycleEvent(Message): +class ExecutionStarted(Message): node: FlowNode pid: int -class ExecutionStarted(CommandLifecycleEvent): - pass - - -class ExecutionCompleted(CommandLifecycleEvent): +class ExecutionCompleted(Message): + node: FlowNode + pid: int exit_code: int -class CommandMessage(Message): +class ExecutionOutput(Message): node: FlowNode text: str diff --git a/synthesize/renderer.py b/synthesize/renderer.py index 7bc08ff..c9eef00 100644 --- a/synthesize/renderer.py +++ b/synthesize/renderer.py @@ -15,9 +15,8 @@ from watchfiles import Change from synthesize.messages import ( - CommandLifecycleEvent, - CommandMessage, ExecutionCompleted, + ExecutionOutput, ExecutionStarted, Message, WatchPathChanged, @@ -53,16 +52,10 @@ def __exit__( def handle_message(self, message: Message) -> None: match message: - case CommandMessage() as msg: + case ExecutionOutput() as msg: self.handle_command_message(msg) - case ExecutionStarted() as msg: - self.handle_lifecycle_message(msg) - - case ExecutionCompleted() as msg: - self.handle_lifecycle_message(msg) - - case WatchPathChanged() as msg: + case ExecutionStarted() | ExecutionCompleted() | WatchPathChanged() as msg: self.handle_lifecycle_message(msg) self.update(message) @@ -92,13 +85,13 @@ def info(self, event: Message) -> RenderableType: return Group(Rule(style=(Style(color="green" if running_targets else "yellow"))), table) def render_prefix( - self, message: CommandMessage | CommandLifecycleEvent | WatchPathChanged + self, message: ExecutionOutput | ExecutionStarted | ExecutionCompleted | WatchPathChanged ) -> str: return prefix_format.format_map( {"id": message.node.id, "timestamp": message.timestamp} ).ljust(self.prefix_width) - def handle_command_message(self, message: CommandMessage) -> None: + def handle_command_message(self, message: ExecutionOutput) -> None: prefix = Text( self.render_prefix(message), style=Style(color=message.node.color),