Пример #1
0
    def test_ConfigFileTask(self):
        """Simple test case for config overrides in file
        """
        builder = PipelineBuilder(TaskFactoryMock())
        # make simple pipeline
        builder.addTask("TaskOne", "task")
        builder.configOverride("task", "field=value")
        pipeline = builder.pipeline()
        self.assertEqual(pipeline[0].config.field, "value")

        # save config to file for next test
        overrides = NamedTemporaryFile(mode="wt", delete=False)
        pipeline[0].config.saveToStream(overrides)
        fname = overrides.name
        del overrides

        builder = PipelineBuilder(TaskFactoryMock())
        builder.addTask("TaskOne", "task")
        builder.configOverrideFile("task", fname)
        pipeline = builder.pipeline()
        self.assertEqual(pipeline[0].config.field, "value")

        os.unlink(fname)

        # unknown label should raise LookupError
        with self.assertRaises(LookupError):
            builder.configOverrideFile("label", "/dev/null")
Пример #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