Coverage for python/lsst/ctrl/mpexec/cli/cmd/commands.py : 88%

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/>.
22import click
24from lsst.daf.butler.cli.opt import (config_file_option,
25 config_option,
26 options_file_option)
27from lsst.daf.butler.cli.utils import (cli_handle_exception,
28 Mocker,
29 MWCtxObj,
30 option_section,
31 unwrap)
32import lsst.obs.base.cli.opt as obsBaseOpts
33from .. import opt as ctrlMpExecOpts
34from .. import script
35from ..utils import makePipelineActions, PipetaskCommand
38epilog = unwrap("""Notes:
40--task, --delete, --config, --config-file, and --instrument action options can
41appear multiple times; all values are used, in order left to right.
43FILE reads command-line options from the specified file. Data may be
44distributed among multiple lines (e.g. one option per line). Data after # is
45treated as a comment and ignored. Blank lines and lines starting with # are
46ignored.)
47""")
50def _doBuild(ctx, **kwargs):
51 # The pipeline actions (task, delete, config, config_file, and instrument)
52 # must be handled in the order they appear on the command line, but the CLI
53 # specification gives them all different option names. So, instead of using
54 # the individual action options as they appear in kwargs (because
55 # invocation order can't be known), we capture the CLI arguments by
56 # overriding `click.Command.parse_args` and save them in the Context's
57 # `obj` parameter. We use `makePipelineActions` to create a list of
58 # pipeline actions from the CLI arguments and pass that list to the script
59 # function using the `pipeline_actions` kwarg name, and remove the action
60 # options from kwargs.
61 for pipelineAction in (ctrlMpExecOpts.task_option.name(), ctrlMpExecOpts.delete_option.name(),
62 config_option.name(), config_file_option.name(),
63 obsBaseOpts.instrument_option.name()):
64 kwargs.pop(pipelineAction)
65 kwargs['pipeline_actions'] = makePipelineActions(MWCtxObj.getFrom(ctx).args)
66 return cli_handle_exception(script.build, **kwargs)
69@click.command(cls=PipetaskCommand, epilog=epilog, short_help="Build pipeline definition.")
70@click.pass_context
71@ctrlMpExecOpts.show_option()
72@ctrlMpExecOpts.pipeline_build_options()
73@option_section(sectionText="")
74@options_file_option()
75def build(ctx, **kwargs):
76 """Build and optionally save pipeline definition.
78 This does not require input data to be specified.
79 """
80 _doBuild(ctx, **kwargs)
83@click.command(cls=PipetaskCommand, epilog=epilog)
84@click.pass_context
85@ctrlMpExecOpts.show_option()
86@ctrlMpExecOpts.pipeline_build_options()
87@ctrlMpExecOpts.qgraph_options()
88@ctrlMpExecOpts.butler_options()
89@option_section(sectionText="")
90@options_file_option()
91def qgraph(ctx, **kwargs):
92 """Build and optionally save quantum graph.
93 """
94 pipeline = _doBuild(ctx, **kwargs)
95 cli_handle_exception(script.qgraph, pipelineObj=pipeline, **kwargs)
98@click.command(cls=PipetaskCommand, epilog=epilog)
99@click.pass_context
100@ctrlMpExecOpts.debug_option()
101@ctrlMpExecOpts.show_option()
102@ctrlMpExecOpts.pipeline_build_options()
103@ctrlMpExecOpts.qgraph_options()
104@ctrlMpExecOpts.butler_options()
105@ctrlMpExecOpts.execution_options()
106@ctrlMpExecOpts.meta_info_options()
107@option_section(sectionText="")
108@options_file_option()
109# --call-mocker is for use with test code, it is not intended for CLI or other
110# non-testing use. It allows this command function to be executed
111# programatically and have it call Mocker with its kwargs, which can the be
112# gotten from Mocker later. At some point, ctrl_mpexec should stop passing
113# around a SimpleNamespace of arguments, which would make this workaround
114# unnecessary.
115@click.option("--call-mocker",
116 is_flag=True,
117 hidden=True) # do not show this option in the help menu.
118def run(ctx, **kwargs):
119 """Build and execute pipeline and quantum graph.
120 """
121 if kwargs["call_mocker"]: 121 ↛ 124line 121 didn't jump to line 124, because the condition on line 121 was never false
122 Mocker(**kwargs)
123 return
124 pipeline = _doBuild(ctx, **kwargs)
125 qgraph = cli_handle_exception(script.qgraph, pipelineObj=pipeline, **kwargs)
126 cli_handle_exception(script.run, qgraphObj=qgraph, **kwargs)