Skip to content
This repository was archived by the owner on Apr 14, 2026. It is now read-only.

Commit b0610fc

Browse files
committed
Stdout/stderr as string outputs
1 parent e8ff6c3 commit b0610fc

6 files changed

Lines changed: 131 additions & 109 deletions

File tree

poetry.lock

Lines changed: 97 additions & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "styxdefs"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "Styx definitions and minimal runtime"
55
authors = ["Florian Rupprecht <33600480+nx10@users.noreply.github.com>"]
66
license = "MIT License"
@@ -14,8 +14,8 @@ python = ">=3.10"
1414
pytest = "^8.2.1"
1515
mypy = "^1.10.0"
1616
pre-commit = "^4.0.1"
17-
pytest-cov = ">=5,<7"
18-
ruff = ">=0.6.9,<0.8.0"
17+
pytest-cov = "^6.0.0"
18+
ruff = "^0.8.0"
1919

2020
[tool.poetry.group.docs.dependencies]
2121
pdoc = "^15.0.0"

src/styxdefs/dry_runner.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Dummy runner for debugging purposes."""
22

33
import pathlib
4+
import typing
45

56
from .types import Execution, InputPathType, Metadata, OutputPathType, Runner
67

@@ -31,7 +32,12 @@ def output_file(self, local_file: str, optional: bool = False) -> OutputPathType
3132
"""Resolve output file."""
3233
return pathlib.Path(local_file)
3334

34-
def run(self, cargs: list[str]) -> None:
35+
def run(
36+
self,
37+
cargs: list[str],
38+
handle_stdout: typing.Callable[[str], None] | None,
39+
handle_stderr: typing.Callable[[str], None] | None,
40+
) -> None:
3541
"""Execute command (in this dry runner this only captures the outputs)."""
3642
self.last_cargs = cargs
3743

src/styxdefs/local_runner.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import pathlib
66
import shlex
7+
import typing
78
from collections import deque
89
from concurrent.futures import ThreadPoolExecutor
910
from datetime import datetime
@@ -56,15 +57,21 @@ def output_file(self, local_file: str, optional: bool = False) -> OutputPathType
5657
"""Resolve local output files."""
5758
return self.output_dir / local_file
5859

59-
def run(self, cargs: list[str]) -> None:
60+
def run(
61+
self,
62+
cargs: list[str],
63+
handle_stdout: typing.Callable[[str], None] | None,
64+
handle_stderr: typing.Callable[[str], None] | None,
65+
) -> None:
6066
"""Run the command."""
6167
self.logger.debug(f"Running command: {shlex.join(cargs)}")
6268

63-
def _stdout_handler(line: str) -> None:
64-
self.logger.info(line)
65-
66-
def _stderr_handler(line: str) -> None:
67-
self.logger.error(line)
69+
_stdout_handler = (
70+
handle_stdout if handle_stdout else lambda line: self.logger.info(line)
71+
)
72+
_stderr_handler = (
73+
handle_stderr if handle_stderr else lambda line: self.logger.error(line)
74+
)
6875

6976
time_start = datetime.now()
7077
with Popen(

src/styxdefs/types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,20 @@ def input_file(
3838
"""
3939
...
4040

41-
def run(self, cargs: list[str]) -> None:
41+
def run(
42+
self,
43+
cargs: list[str],
44+
handle_stdout: typing.Callable[[str], None] | None,
45+
handle_stderr: typing.Callable[[str], None] | None,
46+
) -> None:
4247
"""Run the command.
4348
4449
Args:
4550
cargs: A list of command arguments.
51+
handle_stdout: If defined the runner must forward stdout output to this\
52+
(may be called multiple times).
53+
handle_stderr: If defined the runner must forward stderr output to this\
54+
(may be called multiple times).
4655
4756
Note:
4857
Called after all `Execution.input_file()`

tests/test_local_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_local_runner(tmp_path: pathlib.Path) -> None:
2020
input_file = x.input_file("abc")
2121
output_file = x.output_file("def")
2222
if os.name == "posix":
23-
x.run(["ls"])
23+
x.run(["ls"], None, None)
2424

2525
assert pathlib.Path(input_file).name == "abc"
2626
assert output_file.is_relative_to(tmp_path / "xyz")

0 commit comments

Comments
 (0)