def test_substituteDatatypeNames(self):
        """Simple test case for substituteDatatypeNames method
        """
        builder = PipelineBuilder(TaskFactoryMock())
        builder.addTask("TaskOne", "task")
        pipeline = builder.pipeline()
        self.assertEqual(pipeline[0].config.schema.name, "schema")

        builder = PipelineBuilder(TaskFactoryMock())
        builder.addTask("TaskOne", "task")
        builder.substituteDatatypeNames("task", {"template": "extra_"})
        pipeline = builder.pipeline()
        self.assertEqual(pipeline[0].config.schema.name, "extra_schema")
Ejemplo n.º 2
0
    def makePipeline(self, taskFactory, args):
        """Build a pipeline from command line arguments.

        Parameters
        ----------
        taskFactory : `~lsst.pipe.base.TaskFactory`
            Task factory.
        args : `argparse.Namespace`
            Parsed command line

        Returns
        -------
        pipeline : `~lsst.pipe.base.Pipeline`
        """
        # read existing pipeline from pickle file
        pipeline = None
        if args.pipeline:
            with open(args.pipeline, 'rb') as pickleFile:
                pipeline = pickle.load(pickleFile)
                if not isinstance(pipeline, Pipeline):
                    raise TypeError(
                        "Pipeline pickle file has incorrect object type: {}".
                        format(type(pipeline)))

        pipeBuilder = PipelineBuilder(taskFactory, pipeline)

        # loop over all pipeline actions and apply them in order
        for action in args.pipeline_actions:

            if action.action == "new_task":

                pipeBuilder.addTask(action.value, action.label)

            elif action.action == "delete_task":

                pipeBuilder.deleteTask(action.label)

            elif action.action == "move_task":

                pipeBuilder.moveTask(action.label, action.value)

            elif action.action == "relabel":

                pipeBuilder.labelTask(action.label, action.value)

            elif action.action == "config":

                pipeBuilder.configOverride(action.label, action.value)

            elif action.action == "configfile":

                pipeBuilder.configOverrideFile(action.label, action.value)

            elif action.action == 'name_templates':

                pipeBuilder.substituteDatatypeNames(action.label, action.value)

            else:

                raise ValueError(
                    f"Unexpected pipeline action: {action.action}")

        pipeline = pipeBuilder.pipeline(args.order_pipeline)

        if args.save_pipeline:
            with open(args.save_pipeline, "wb") as pickleFile:
                pickle.dump(pipeline, pickleFile)

        if args.pipeline_dot:
            pipeline2dot(pipeline, args.pipeline_dot, taskFactory)

        return pipeline