Pipeline
cuprum/sh/pipeline.py, the source of Pipeline
class Pipeline(parts: 'tuple[SafeCmd, ...]')
A sequence of SafeCmd stages connected via stdout/stdin piping.
Attributes
partstuple[SafeCmd, ...]- The stages in execution order. The first stage's stdin is the pipeline's stdin and the last stage's stdout is its stdout; each intervening stage feeds the next. Always at least
_MIN_PIPELINE_STAGESlong, as__post_init__enforces.
6 members
field Pipeline.parts
parts: 'tuple[SafeCmd, ...]'
classmethod Pipeline.concat
def concat(
left: 'SafeCmd | Pipeline',
right: 'SafeCmd | Pipeline',
) -> 'Pipeline'
Compose a pipeline from two stage operands.
Parameters
leftSafeCmd | Pipeline- A command or pipeline whose stages come first.
rightSafeCmd | Pipeline- A command or pipeline whose stages follow
left's.
Returns
- Pipeline
- A pipeline whose stages are *left*'s followed by *right*'s.
method Pipeline.run
async def run(
*,
output: RunOutputOptions | None = None,
timeout: float | None = None,
context: ExecutionContext | None = None,
**deprecated_flags: typ.Unpack[_DeprecatedOutputFlags],
) -> PipelineResult
Execute the pipeline asynchronously with streaming and backpressure.
Parameters
outputRunOutputOptions | None, default=None- Capture and echo settings for every observed pipeline stream. The default bounds each echoed line to 64 KiB;
Noneformax_echo_line_bytesrestores unbounded mirroring without changing capture. timeoutfloat | None, default=None- Maximum pipeline execution time in seconds.
contextExecutionContext | None, default=None- Execution settings, including echo sinks and text encoding.
**deprecated_flagsbool- Deprecated
captureandechokeyword arguments. Do not combine them withoutput.
Returns
- PipelineResult
- The outcome for every stage and complete captured streams when capture is enabled.
Raises
ValueError- If
outputis combined with deprecated flags, or if it names astdin/stdout/stderrtarget, which pipeline stages do not honour. PermissionError- If a pipeline command is not allowed by the active scope.
TimeoutError- If execution exceeds the effective timeout.
method Pipeline.run_sync
def run_sync(
*,
output: RunOutputOptions | None = None,
timeout: float | None = None,
context: ExecutionContext | None = None,
**deprecated_flags: typ.Unpack[_DeprecatedOutputFlags],
) -> PipelineResult
Execute the pipeline synchronously via asyncio.run.
Parameters
outputRunOutputOptions | None, default=None- Capture and echo settings. The 64 KiB default bounds mirrored lines;
max_echo_line_bytes=Nonerestores unbounded echoing while leaving captured output complete. timeoutfloat | None, default=None- Maximum pipeline execution time in seconds.
contextExecutionContext | None, default=None- Execution settings, including echo sinks and text encoding.
**deprecated_flagsbool- Deprecated
captureandechokeyword arguments. Do not combine them withoutput.
Returns
- PipelineResult
- The outcome for every stage and complete captured streams when capture is enabled.
Raises
ValueError- If
outputis combined with deprecated flags, or if it names astdin/stdout/stderrtarget, which pipeline stages do not honour. PermissionError- If a pipeline command is not allowed by the active scope.
TimeoutError- If execution exceeds the effective timeout.
method Pipeline.run_bytes
async def run_bytes(
*,
output: RunOutputOptions | None = None,
timeout: float | None = None,
context: ExecutionContext | None = None,
) -> BytesPipelineResult
Execute the pipeline, capturing its output as bytes.
Every stage runs exactly as it does under run(); the difference is what the parent keeps. Each stage's captured stderr and the final stage's captured stdout are reported as the child wrote them, which is what lets a pipeline relay a binary payload end to end. An interior stage's stdout is consumed by the next stage rather than captured, so it is reported as None exactly as it is in text mode.
The pipeline's own stdin feeding is unchanged: the first stage reads from the parent process's stdin, as it always does, and no stage's output is interpreted on the way through.
Parameters
outputRunOutputOptions | None, default=None- Capture and echo settings for every observed pipeline stream.
on_lineis rejected: bytes mode returns each stream's own bytes, so a callback carrying decoded text would be a second, contradictory contract for the same stream. Use the text-mode entry point when lines are wanted. timeoutfloat | None, default=None- Maximum pipeline execution time in seconds.
contextExecutionContext | None, default=None- Execution settings, including echo sinks and text encoding.
Returns
- BytesPipelineResult
- Per-stage outcomes plus the final stage's captured stdout, as bytes wherever a stream was captured.
Raises
ValueError- If
output.on_lineis set. PermissionError- If a pipeline command is not allowed by the active scope.
TimeoutError- If execution exceeds the effective timeout.
method Pipeline.run_bytes_sync
def run_bytes_sync(
*,
output: RunOutputOptions | None = None,
timeout: float | None = None,
context: ExecutionContext | None = None,
) -> BytesPipelineResult
Execute the pipeline synchronously, capturing its output as bytes.
Parameters
outputRunOutputOptions | None, default=None- Capture and echo settings.
on_lineis rejected: bytes mode returns each stream's own bytes, so a callback carrying decoded text would be a second, contradictory contract for the same stream. Use the text-mode entry point when lines are wanted. timeoutfloat | None, default=None- Maximum pipeline execution time in seconds.
contextExecutionContext | None, default=None- Execution settings, including echo sinks and text encoding.
Returns
- BytesPipelineResult
- Per-stage outcomes plus the final stage's captured stdout, as bytes wherever a stream was captured.
Raises
ValueError- If
output.on_lineis set. PermissionError- If a pipeline command is not allowed by the active scope.
TimeoutError- If execution exceeds the effective timeout.