Coverage for python/lsst/ctrl/mpexec/cli/script/build.py: 26%
15 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-04 09:50 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-04 09:50 +0000
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 software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
28from types import SimpleNamespace
30from lsst.daf.butler import Butler
32from ... import CmdLineFwk
33from ..utils import _PipelineAction
36def build( # type: ignore
37 order_pipeline,
38 pipeline,
39 pipeline_actions,
40 pipeline_dot,
41 save_pipeline,
42 show,
43 butler_config=None,
44 **kwargs,
45):
46 """Implement the command line interface `pipetask build` subcommand.
48 Should only be called by command line tools and unit test code that tests
49 this function.
51 Build and optionally save pipeline definition.
53 Returns the pipeline instance that was built, for testing and for using
54 this function with other script functions.
56 Parameters
57 ----------
58 order_pipeline : `bool`
59 If true, order tasks in pipeline based on their data dependencies,
60 ordering is performed as last step before saving or executing pipeline.
61 pipeline_actions : `list` [`PipelineAction`]] or `PipelineAction`
62 A list of pipeline actions in the order they should be executed.
63 pipeline_dot : `str`
64 Path location for storing GraphViz DOT representation of a pipeline.
65 pipeline : `str`
66 Path location of a pipeline definition file in YAML format.
67 save_pipeline : `str`
68 Path location for storing resulting pipeline definition in YAML format.
69 show : `lsst.ctrl.mpexec.showInfo.ShowInfo`
70 Descriptions of what to dump to stdout.
71 butler_config : `str`, `dict`, or `lsst.daf.butler.Config`, optional
72 If `str`, `butler_config` is the path location of the gen3
73 butler/registry config file. If `dict`, `butler_config` is key value
74 pairs used to init or update the `lsst.daf.butler.Config` instance. If
75 `Config`, it is the object used to configure a Butler.
76 Only used to resolve pipeline graphs for --show pipeline-graph and
77 --show task-graph.
78 **kwargs
79 Ignored; click commands may accept options for more than one script
80 function and pass all the option kwargs to each of the script functions
81 which ingore these unused kwargs.
83 Returns
84 -------
85 pipeline : `lsst.pipe.base.Pipeline`
86 The pipeline instance that was built.
88 Raises
89 ------
90 Exception
91 Raised if there is a failure building the pipeline.
92 """
93 # If pipeline_actions is a single instance, not a list, then put it in
94 # a list. _PipelineAction is a namedtuple, so we can't use
95 # `lsst.utils.iteration.iterable` because a namedtuple *is* iterable,
96 # but we need a list of _PipelineAction.
97 if isinstance(pipeline_actions, _PipelineAction):
98 pipeline_actions = (pipeline_actions,)
100 args = SimpleNamespace(
101 pipeline=pipeline,
102 pipeline_actions=pipeline_actions,
103 pipeline_dot=pipeline_dot,
104 save_pipeline=save_pipeline,
105 )
107 f = CmdLineFwk()
109 # Will raise an exception if it fails to build the pipeline.
110 pipeline = f.makePipeline(args)
112 if butler_config is not None:
113 butler = Butler.from_config(butler_config, writeable=False)
114 else:
115 butler = None
117 show.show_pipeline_info(pipeline, butler=butler)
119 return pipeline