Stream Factories

shtk.StreamFactory subclasses are templates used to define the properties of shtk.Stream instances. shtk.Stream instances are pairs of file-like objects (one for reading data from the process, one for writing data to the process) used for communication with running processes.

shtk.StreamFactory instances are typically constructed via calls to shtk.PipelineNodeFactory.stdin(), shtk.PipelineNodeFactory.stdout(), and shtk.PipelineNodeFactory.stderr().

shtk.StreamFactory

class shtk.StreamFactory

Bases: ABC

Base class for templates creating associated Stream instances

abstract build(job)

Instantiates the Stream instance

Parameters

job (Job) – job to use for current working directory and environment variables.

Returns

The constructed Stream instance.

Return type

Stream

shtk.FileStreamFactory

class shtk.FileStreamFactory(partial_path, mode)

Bases: StreamFactory

Creates a template for FileStream instances

Parameters
  • partial_path (str or pathlib.Path) – The absolute or job.cwd relative path to the file.

  • mode (str) – The mode to pass to open() when instantiating the FileStream.

partial_path

The absolute or job.cwd relative path to the file.

Type

pathlib.Path

mode

The mode to pass to open() when instantiating the FileStream.

Type

str

build(job)

Instantiates the FileStream instance

Parameters

job (Job) – job to use for current working directory and environment variables.

Returns

The constructed FileStream instance.

Return type

FileStream

shtk.ManualStreamFactory

class shtk.ManualStreamFactory(fileobj_r=None, fileobj_w=None)

Bases: StreamFactory

Creates a template for ManualStream instances

Parameters
  • fileobj_r (file-like or None) – A file-like object suitable for reading. None implies os.devnull should be used (Default value = None).

  • fileobj_w (file-like or None) – A file-like object suitable for writing. None implies os.devnull should be used (Default value = None).

fileobj_r

A file-like object suitable for reading. None implies os.devnull should be used.

Type

file-like or None

fileobj_w

A file-like object suitable for writing. None implies os.devnull should be used.

Type

file-like or None

build(job)

Instantiates the ManualStream instance

Parameters

job (Job) – job to use for current working directory and environment variables.

Returns

The constructed ManualStream instance.

Return type

ManualStream

shtk.NullStreamFactory

class shtk.NullStreamFactory

Bases: StreamFactory

Creates a template for NullStream instances

build(job)

Instantiates the NullStream instance

Parameters

job (Job) – job to use for current working directory and environment variables.

Returns

The constructed NullStream instance.

Return type

NullStream

shtk.PipeStreamFactory

class shtk.PipeStreamFactory(flags=0)

Bases: StreamFactory

Creates a template for PipeStream instances

Parameters

flags (int) – flags to pass to PipeStream constructor (Default value = 0).

flags

flags to pass to PipeStream constructor

Type

int

build(job)

Instantiates the PipeStream instance

Parameters

job (Job) – job to use for current working directory and environment variables.

Returns

The constructed PipeStream instance.

Return type

PipeStream