22 """Module defining PipelineBuilder class and related methods. 25 __all__ = [
"PipelineBuilder"]
36 from .configOverrides
import ConfigOverrides
37 from .pipeline
import Pipeline, TaskDef
38 from .
import pipeTools
45 _LOG = logging.getLogger(__name__.partition(
".")[2])
53 """PipelineBuilder class is responsible for building task pipeline. 55 The class provides a set of methods to manipulate pipeline by adding, 56 deleting, re-ordering tasks in pipeline and changing their labels or 61 taskFactory : `TaskFactory` 62 Factory object used to load/instantiate PipelineTasks 63 pipeline : `Pipeline`, optional 64 Initial pipeline to be modified, if `None` then new empty pipeline 67 def __init__(self, taskFactory, pipeline=None):
74 """Return updated pipeline instance. 76 Pipeline will be checked for possible inconsistencies before 81 ordered : `bool`, optional 82 If `True` then order resulting pipeline according to Task data 92 Raised if any inconsistencies are detected in pipeline definition, 93 see `pipeTools.orderPipeline` for list of exception types. 99 return orderedPipeline
104 """Append new task to a pipeline. 109 Name of the new task, can be either full class name including 110 package and module, or just a class name to be searched in 111 known packages and modules. 112 label : `str`, optional 113 Label for new task, if `None` then task class name is used as 117 taskClass, taskName = self.
_taskFactory.loadTaskClass(taskName)
121 label = taskName.rpartition(
'.')[2]
122 if self.
_pipeline.labelIndex(label) >= 0:
123 raise LookupError(
"Task label (or name) is not unique: " + label)
126 config = taskClass.ConfigClass()
129 taskClass=taskClass, label=label))
132 """Remove task from a pipeline. 137 Label of the task to remove. 141 raise LookupError(
"Task label is not found: " + label)
145 """Move task to a new position in a pipeline. 150 Label of the task to move. 156 raise LookupError(
"Task label is not found: " + label)
160 """Change task label. 165 Existing label of the task. 167 New label of the task. 171 raise LookupError(
"Task label is not found: " + label)
173 if newLabel != label
and self.
_pipeline.labelIndex(newLabel) >= 0:
174 raise LookupError(
"New task label is not unique: " + label)
178 """Apply single config override. 185 String in the form ``"param=value"`` or ``"parm.subpar=value"``, 186 ``value`` can be a Python constant or a list of constants. 190 raise LookupError(
"Task label is not found: " + label)
191 key, sep, val = value.partition(
'=')
193 overrides.addValueOverride(key, val)
194 overrides.applyTo(self.
_pipeline[idx].config)
197 """Apply overrides from file. 204 Path to file with overrides. 208 raise LookupError(
"Task label is not found: " + label)
210 overrides.addFileOverride(path)
211 overrides.applyTo(self.
_pipeline[idx].config)
214 """Apply name string formatting to config file 220 String of the form of a dictionary of template keyword to value 224 raise LookupError(
"Task label is not found: " + label)
227 parsedNamesDict = ast.literal_eval(value)
228 if not isinstance(parsedNamesDict, dict):
231 raise pexExceptions.RuntimeError(f
"Unable parse --dataset-name-substitution {value} " 235 overrides.addDatasetNameSubstitution(parsedNamesDict)
236 overrides.applyTo(self.
_pipeline[idx].config)
def configOverride(self, label, value)
def pipeline(self, ordered=False)
def addTask(self, taskName, label=None)
def deleteTask(self, label)
def __init__(self, taskFactory, pipeline=None)
def labelTask(self, label, newLabel)
def substituteDatatypeNames(self, label, value)
def configOverrideFile(self, label, path)
def moveTask(self, label, newIndex)