httk.workflow.languages.pwd¶
Running one Python Workflow Definition document as one httk₂ job.
The Python Workflow Definition
(PWD) is a small JSON exchange format: a list of nodes and a list of
edges. A node is a Python function named module.function, a literal
input, or a named output; an edge connects one node’s output port to another
node’s input port. The format is deliberately machine-facing — several workflow
engines read and write it — and this module is httk₂ reading it.
from httk.workflow import Workspace, new_job
workspace = Workspace.initialize("workflow-workspace")
job = new_job(workspace, "workflow.json", parameters={"pwd_module_path": ["."]})
The import is one way and produces exactly one job. The whole graph runs inside
that job, sequentially, in topological order, by the packaged
pwd_runner.py — no runner file is written per workflow, and no per-node job
is created: a PWD node is one Python call, which is not worth a claim, a lease
and a process of its own.
The document travels in the job’s parameters when it fits within
maximum_embedded_bytes, and in files/pwd.json with a document pointer when
it does not, because parameters is bounded by
MAXIMUM_PARAMETERS_BYTES and a generated document can
be much larger than that.
Warning
Running a PWD document executes the Python functions it names. There is
no sandbox and there cannot be one: the format’s whole content is
module.function references. Import a document exactly as carefully as you
would run the module it names. Passing allowed_modules records an allowlist
of module prefixes in the job, which the runner refuses to import outside of.
Attributes¶
Exceptions¶
A document that is not a Python Workflow Definition this importer accepts. |
Classes¶
The named input and output ports of one language document. |
|
The data supplied when preparing one language workflow. |
|
The files, runner, and hooks prepared for one language workflow. |
|
The operations a workflow language exposes to the common layer. |
|
One validated PWD document, and the order its function nodes run in. |
Functions¶
|
Return the |
|
Read and validate one PWD document from path. |
|
Validate the shape of one PWD document and order its nodes. |
|
Convert one PWD runner output document into provenance-capable records. |
Package Contents¶
- class httk.workflow.languages.pwd.LanguagePorts[source]¶
The named input and output ports of one language document.
- Parameters:
inputs – Names of the document’s input ports.
outputs – Names of the document’s output ports.
- class httk.workflow.languages.pwd.LanguageRequest[source]¶
The data supplied when preparing one language workflow.
- Parameters:
workflow_id – Identify the workflow being prepared.
directory – Locate the workflow package, when it has one.
document – Locate the source workflow document, when it has one.
runner_options – Supply options for the language runner.
inputs – Describe the workflow inputs.
outputs – Describe the requested workflow outputs.
parameters – Describe the declared workflow parameters.
environment – Describe the declared workflow environment.
excluded_members – Package members the realization must not stage.
- directory: pathlib.Path | None¶
- document: pathlib.Path | None¶
- runner_options: collections.abc.Mapping[str, object]¶
- inputs: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- outputs: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- parameters: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- environment: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- class httk.workflow.languages.pwd.LanguageScaffold[source]¶
The files, runner, and hooks prepared for one language workflow.
- Parameters:
documents – Text or byte documents to write into the payload.
files – Files to stage into the payload.
parameters – Job parameters produced by preparation.
runner – Runner description for the job, when one is supplied.
runner_executor – Select the runner executor.
payload_runner – Name a runner staged in the payload.
workdir_path – Name the workdir below the job payload.
required_capabilities – Require these manager capabilities.
reserved_parameters – Names reserved for per-job realization output.
warnings – Preserve preparation warnings.
instantiate – Supply the per-job hook called after input staging.
finalize – Transform the per-job
JobSpecimmediately before its payload is prepared.
- documents: collections.abc.Mapping[str, str | bytes]¶
- files: collections.abc.Mapping[str, pathlib.Path]¶
- parameters: collections.abc.Mapping[str, object]¶
- runner: collections.abc.Mapping[str, object] | None¶
- instantiate: collections.abc.Callable[[httk.workflow.scaffold.InstantiateContext], object] | None = None¶
- finalize: collections.abc.Callable[[httk.workflow.runtime_builders.JobSpec], httk.workflow.runtime_builders.JobSpec] | None = None¶
- class httk.workflow.languages.pwd.WorkflowLanguage[source]¶
The operations a workflow language exposes to the common layer.
- Parameters:
name – Name the language.
steps – Declare the runner’s steps.
initial_step – Select the runner’s initial step.
matches – Identify documents belonging to the language.
ports – Read the input and output ports of a document.
validate_runner – Validate runner options for a document.
prepare – Prepare a language request for execution.
collect – Convert a completed job record into language outputs.
document_policy – State whether package manifests require, allow, or forbid a source document.
open_ports – Skip manifest port validation when document ports cannot be enumerated statically.
has_default_collector – Provide a default collector path.
allows_modes – Permit manifest data and workdir mode overrides.
environment – Declare language-provided environment metadata.
required_modules – Name the importable modules a job of this language needs at run time.
- matches: collections.abc.Callable[[pathlib.Path], bool]¶
- ports: collections.abc.Callable[[pathlib.Path], LanguagePorts]¶
- validate_runner: collections.abc.Callable[[collections.abc.Mapping[str, object], pathlib.Path], None]¶
- prepare: collections.abc.Callable[[LanguageRequest], LanguageScaffold]¶
- collect: collections.abc.Callable[[httk.workflow.collecting.JobRecord], collections.abc.Mapping[str, object]]¶
- document_policy: DocumentPolicy = 'required'¶
- environment: collections.abc.Mapping[str, collections.abc.Mapping[str, object]]¶
- httk.workflow.languages.pwd.runner_reference(package, name)[source]¶
Return the
runnermember of ajob.jsonrunning one packaged runner.The reserved
pkg:form names the runner inside its own consumer package, and the digest is taken from the installed bytes, which is exactly what the manager verifies before it stages and executes them.
- httk.workflow.languages.pwd.MAXIMUM_PARAMETERS_BYTES = 262144¶
- exception httk.workflow.languages.pwd.PwdFormatError[source]¶
Bases:
ValueErrorA document that is not a Python Workflow Definition this importer accepts.
- class httk.workflow.languages.pwd.PwdDocument[source]¶
One validated PWD document, and the order its function nodes run in.
- Parameters:
raw – Preserve the validated source document.
nodes – Preserve validated nodes keyed by identifier.
edges – Preserve validated graph edges.
order – Record the topological node execution order.
- httk.workflow.languages.pwd.load_pwd_document(path, *, allow_unknown_version=False)[source]¶
Read and validate one PWD document from path.
- Parameters:
path (str | os.PathLike[str]) – Read the PWD JSON document at this path.
allow_unknown_version (bool) – Try versions outside the supported set.
- Returns:
The validated PWD document.
- Raises:
httk.workflow.languages.pwd.PwdFormatError – If the file cannot be read, parsed, or validated.
- Return type:
- httk.workflow.languages.pwd.validate_pwd_document(raw, *, source='the document', allow_unknown_version=False)[source]¶
Validate the shape of one PWD document and order its nodes.
Every member the format defines is checked; every member it does not define is preserved untouched, so a document carrying an engine’s own annotations survives the round trip into the job payload. When the
python-workflow-definitionpackage happens to be installed it is asked for a second opinion — it is never a dependency of httk-workflow, only a stricter validator when it is there.- Parameters:
- Returns:
The validated PWD document.
- Raises:
httk.workflow.languages.pwd.PwdFormatError – If the document shape, graph, or version is invalid.
- Return type: