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

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
23from functools import partial
25from lsst.daf.butler.cli.opt import (config_file_option,
26 config_option,
27 log_level_option)
28from lsst.daf.butler.cli.utils import (cli_handle_exception,
29 MWCommand,
30 MWCtxObj,
31 option_section,
32 split_kv,
33 unwrap)
34from lsst.obs.base.cli.opt import instrument_option
35from .. import opt
36from .. import script
37from ..utils import makePipelineActions
40instrumentOptionHelp = ("Add an instrument which will be used to load config overrides when defining a "
41 "pipeline. This must be the fully qualified class name.")
44forwardEpilog = unwrap("""Options marked with (f) are forwarded to the next subcommand if multiple subcommands
45 are chained in the same command execution. Previous values may be overridden by passing new
46 option values into the next subcommand.""")
48buildEpilog = unwrap(f"""Notes:
50--task, --delete, --config, --config-file, and --instrument action options can
51appear multiple times; all values are used, in order left to right.
53FILE reads command-line options from the specified file. Data may be
54distributed among multiple lines (e.g. one option per line). Data after # is
55treated as a comment and ignored. Blank lines and lines starting with # are
56ignored.)
57""")
59qgraphEpilog = forwardEpilog
61runEpilog = forwardEpilog
64@click.command(cls=MWCommand, epilog=buildEpilog, short_help="Build pipeline definition.")
65@click.pass_context
66@log_level_option()
67@opt.pipeline_option()
68@opt.task_option()
69@opt.delete_option(metavar="LABEL")
70@config_option(metavar="LABEL:NAME=VALUE", multiple=True)
71@config_file_option(help="Configuration override file(s), applies to a task with a given label.",
72 metavar="LABEL:FILE",
73 multiple=True)
74@instrument_option(help=instrumentOptionHelp, metavar="instrument", multiple=True)
75@opt.order_pipeline_option()
76@opt.save_pipeline_option()
77@opt.pipeline_dot_option()
78@opt.show_option()
79def build(ctx, *args, **kwargs):
80 """Build and optionally save pipeline definition.
82 This does not require input data to be specified.
83 """
84 def processor(objs):
85 # The pipeline actions (task, delete, config, config_file, and instrument)
86 # must be handled in the order they appear on the command line, but the CLI
87 # specification gives them all different option names. So, instead of using
88 # the individual action options as they appear in kwargs (because
89 # invocation order can't be known), we capture the CLI arguments by
90 # overriding `click.Command.parse_args` and save them in the Context's
91 # `obj` parameter. We use `makePipelineActions` to create a list of
92 # pipeline actions from the CLI arguments and pass that list to the script
93 # function using the `pipeline_actions` kwarg name, and remove the action
94 # options from kwargs.
95 for pipelineAction in (opt.task_option.name(), opt.delete_option.name(),
96 config_option.name(), config_file_option.name(),
97 instrument_option.name()):
98 kwargs.pop(pipelineAction)
99 kwargs['pipeline_actions'] = makePipelineActions(MWCtxObj.getFrom(ctx).args)
100 objs.pipeline = cli_handle_exception(script.build, *args, **kwargs)
101 return objs
102 return processor
105@click.command(cls=MWCommand, epilog=qgraphEpilog)
106@click.pass_context
107@log_level_option()
108@opt.qgraph_option()
109@opt.skip_existing_option()
110@opt.save_qgraph_option()
111@opt.save_single_quanta_option()
112@opt.qgraph_dot_option()
113@option_section(sectionText="Data repository and selection options:")
114@opt.butler_config_option(forward=True)
115# CLI API says `--input` values should be given like
116# "datasetType:collectionName" or just "datasetType", but CmdLineFwk api
117# wants input values to be a tuple of tuples, where each tuple is
118# ("collectionName", "datasetType"), or (..., "datasetType") with elipsis if no
119# collectionName is provided. Setting `return_type=tuple`, `reverse_kv=True`,
120# and `default_key=...` make `split_kv` callback structure its return value
121# that way.
122@opt.input_option(callback=partial(split_kv, return_type=tuple, default_key=..., reverse_kv=True,
123 unseparated_okay=True),
124 multiple=True,
125 forward=True)
126@opt.output_option(forward=True)
127@opt.output_run_option(forward=True)
128@opt.extend_run_option(forward=True)
129@opt.replace_run_option(forward=True)
130@opt.prune_replaced_option(forward=True)
131@opt.data_query_option(forward=True)
132@option_section(sectionText="Other options:")
133@opt.show_option()
134def qgraph(ctx, *args, **kwargs):
135 """Build and optionally save quantum graph.
136 """
137 def processor(objs):
138 newKwargs = objs.butlerArgs.update(ctx.command.params, MWCtxObj.getFrom(ctx).args, **kwargs)
139 objs.qgraph = cli_handle_exception(script.qgraph, pipeline=objs.pipeline, **newKwargs)
140 return objs
141 return processor
144@click.command(cls=MWCommand, epilog=runEpilog)
145@click.pass_context
146@log_level_option()
147@opt.debug_option()
148@option_section(sectionText="Data repository and selection options:")
149@opt.butler_config_option(forward=True)
150# CLI API says `--input` values should be given like
151# "datasetType:collectionName" or just "datasetType", but CmdLineFwk api
152# wants input values to be a tuple of tuples, where each tuple is
153# ("collectionName", "datasetType"), or (..., "datasetType") - elipsis if no
154# collectionName is provided.
155@opt.input_option(callback=partial(split_kv, return_type=tuple, default_key=..., reverse_kv=True,
156 unseparated_okay=True),
157 multiple=True,
158 forward=True)
159@opt.output_option(forward=True)
160@opt.output_run_option(forward=True)
161@opt.extend_run_option(forward=True)
162@opt.replace_run_option(forward=True)
163@opt.prune_replaced_option(forward=True)
164@opt.data_query_option(forward=True)
165@option_section(sectionText="Execution options:")
166@opt.do_raise_option()
167@opt.profile_option()
168@opt.processes_option()
169@opt.timeout_option()
170@opt.fail_fast_option()
171@opt.graph_fixup_option()
172@option_section(sectionText="Meta-information output options:")
173@opt.skip_init_writes_option()
174@opt.init_only_option()
175@opt.register_dataset_types_option()
176@opt.no_versions_option()
177@opt.skip_existing_option(help=unwrap("""Do not try to overwrite any datasets that might exist in the butler.
178 If not provided then any existing conflicting dataset will cause butler
179 exception."""))
180def run(ctx, *args, **kwargs):
181 """Execute pipeline and quantum graph.
182 """
183 def processor(objs):
184 newKwargs = objs.butlerArgs.update(ctx.command.params, MWCtxObj.getFrom(ctx).args, **kwargs)
185 cli_handle_exception(script.run, qgraph=objs.qgraph, **newKwargs)
186 return objs
187 return processor