pestifer.core.pipeline module¶
Pipeline context for managing passing of information from one task to another via artifacts. All Artifact types are defined in ~pestifer.core.artifacts.
The main task of the pipeline is the _registration_ of Artifacts. This is done primarily via PipelineContext.register().
This method requires an object, a key, the id of the object requesting the registration, and the type of the Artifact.
- class pestifer.core.pipeline.PipelineContext(controller_index: int = 0)[source]¶
Bases:
objectContext for managing the pipeline of artifacts by which tasks communicate.
- head¶
Current artifacts organized into to a dict by their keys
- Type:
- history¶
All non-current artifacts in chronological order by their creation
- Type:
- bury(artifact: Artifact)[source]¶
Bury an artifact in the history without registering it as a current artifact
- Parameters:
artifact (Artifact) – The artifact to bury.
- context_to_string() str[source]¶
Report the current artifacts in the pipeline context.
- Returns:
A string representation of the current artifacts in the pipeline context.
- Return type:
- get_all_file_artifacts(produced_by: object | None = None) FileArtifactList[source]¶
Retrieve a collection of artifacts produced by a specific task or object.
- Parameters:
produced_by (object | None) – The task or object that produced the artifacts to retrieve.
- Returns:
A list of all file artifacts produced by the specified task.
- Return type:
- get_artifact_series_by_key(key: str = '') ArtifactList | FileArtifactList[source]¶
Retrieve a series of artifacts with the same key.
- Parameters:
- Returns:
A list of artifacts associated with the given key, in reverse registration order. If all artifacts filtered are FileArtifacts, returns a FileArtifactList.
- Return type:
- get_current_artifact_data(key: str)[source]¶
Retrieve the data of an artifact by its key.
- Parameters:
key (str) – The key for the artifact to retrieve.
- Returns:
The value of the artifact, or None if not found.
- Return type:
Any
- get_state_artifact(produced_by: object | None = None) StateArtifacts | None[source]¶
Retrieve the most recent StateArtifacts produced by a specific task or object.
- Parameters:
produced_by (object | None) – The task or object that produced the artifacts to retrieve.
- Returns:
The most recent StateArtifacts produced by the specified task, or None if not found.
- Return type:
StateArtifacts | None
- history_to_string() str[source]¶
Report the history of artifacts in the pipeline context.
- Returns:
A string representation of the history of artifacts in the pipeline context.
- Return type:
- import_artifacts(other: PipelineContext)[source]¶
Import artifacts from another pipeline context.
- register(data: object, key: str, requestor: object, artifact_type: type = pestifer.core.artifacts.Artifact | pestifer.core.artifacts.ArtifactList | pestifer.core.artifacts.ArtifactDict, **kwargs) Artifact[source]¶
Artifact registrar. If an artifact with the requested key already exists, and the data is the same, the existing artifact is stamped with the requestor and returned. If the data is different, the existing artifact is moved to history and a new artifact is created, stamped with the requestor, registered as the current artifact, and returned. If no artifact with the requested key exists, a new artifact is created, stamped with the requestor, registered as the current artifact, and returned.
- register_if_exists(data: object, requestor: object, artifact_type: type = <class 'pestifer.core.artifacts.FileArtifact'>, **kwargs) FileArtifact | None[source]¶
Artifact registrar that only registers the artifact if it exists (for file artifacts). If an artifact with the requested key already exists, and the data is the same, the existing artifact is stamped with the requestor and returned. If the data is different, the existing artifact is moved to history and a new artifact is created, stamped with the requestor, registered as the current artifact, and returned. If no artifact with the requested key exists, a new artifact is created, stamped with the requestor, registered as the current artifact, and returned.
- Parameters:
data (object) – The data for the artifact to register.
key (str) – Unique identifier for the artifact.
requestor (object) – The object that is requesting the registration of the artifact. This can be used for logging or tracking purposes.
artifact_type (type) – The type of artifact to create (default is FileArtifact).
**kwargs (dict) – Additional keyword arguments to pass to the artifact constructor.
- Returns:
The registered artifact if it exists, otherwise None.
- Return type:
FileArtifact | None
- rekey(old_key: str, new_key: str)[source]¶
Change the key of an existing artifact in the head.
- Parameters:
- Raises:
ValueError – If the old_key does not exist in the head.