Coverage for python/lsst/ctrl/mpexec/cli/script/build.py : 15%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of ctrl_mpexec.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22from lsst.daf.butler.cli.cliLog import CliLog
23from ... import CmdLineFwk
24from ...cmdLineParser import _PipelineAction
27def build(order_pipeline=None, pipeline=None, pipeline_actions=(), pipeline_dot=None, save_pipeline=None,
28 show=(), log_level=None):
29 """Implements the command line interface `pipetask build` subcommand,
30 should only be called by command line tools and unit test code that tests
31 this function.
33 Build and optionally save pipeline definition.
35 Returns the pipeline instance that was built, for testing and for using
36 this function with other script functions.
38 Parameters
39 ----------
40 order_pipeline : `bool`
41 If true, order tasks in pipeline based on their data dependencies,
42 ordering is performed as last step before saving or executing pipeline.
43 pipeline_actions : `list` [`PipelineAction`]] or `PipelineAction`
44 A list of pipeline actions in the order they should be executed.
45 pipeline_dot : `str`
46 Path location for storing GraphViz DOT representation of a pipeline.
47 pipeline : `str`
48 Path location of a pipeline definition file in YAML format.
49 save_pipeline : `str`
50 Path location for storing resulting pipeline definition in YAML format.
51 show : `list` [`str`]
52 Descriptions of what to dump to stdout.
54 Returns
55 -------
56 pipeline : `lsst.pipe.base.Pipeline`
57 The pipeline instance that was built.
59 Raises
60 ------
61 Exception
62 Raised if there is a failure building the pipeline.
63 """
64 # If pipeline_actions is a single instance, not a list, then put it in
65 # a list. _PipelineAction is a namedtuple, so we can't use
66 # `lsst.daf.butler.core.utils.iterable` because a namedtuple *is* iterable,
67 # but we need a list of _PipelineAction.
68 if isinstance(pipeline_actions, _PipelineAction):
69 pipeline_actions = (pipeline_actions,)
71 if log_level is not None:
72 CliLog.setLogLevels(log_level)
74 class MakePipelineArgs:
75 """A container class for arguments to CmdLineFwk.makePipeline, whose
76 API (currently) is written to accept inputs from argparse in a generic
77 container class.
78 """
79 def __init__(self, pipeline, pipeline_actions, pipeline_dot, save_pipeline):
80 self.pipeline = pipeline
81 self.pipeline_dot = pipeline_dot
82 self.save_pipeline = save_pipeline
83 self.pipeline_actions = pipeline_actions
85 args = MakePipelineArgs(pipeline, pipeline_actions, pipeline_dot, save_pipeline)
87 f = CmdLineFwk()
89 # Will raise an exception if it fails to build the pipeline.
90 pipeline = f.makePipeline(args)
92 class ShowInfoArgs:
93 """A container class for arguments to CmdLineFwk.showInfo, whose
94 API (currently) is written to accept inputs from argparse in a generic
95 container class.
96 """
98 def __init__(self, show):
99 self.show = show
101 args = ShowInfoArgs(show)
102 f.showInfo(args, pipeline)
104 return pipeline