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

Shortcuts 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

41 statements  

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/>. 

21 

22import click 

23import lsst.obs.base.cli.opt as obsBaseOpts 

24from lsst.daf.butler.cli.opt import config_file_option, config_option, options_file_option 

25from lsst.daf.butler.cli.utils import MWCtxObj, catch_and_exit, option_section, unwrap 

26 

27from .. import opt as ctrlMpExecOpts 

28from .. import script 

29from ..utils import PipetaskCommand, makePipelineActions 

30 

31epilog = unwrap( 

32 """Notes: 

33 

34--task, --delete, --config, --config-file, and --instrument action options can 

35appear multiple times; all values are used, in order left to right. 

36 

37FILE reads command-line options from the specified file. Data may be 

38distributed among multiple lines (e.g. one option per line). Data after # is 

39treated as a comment and ignored. Blank lines and lines starting with # are 

40ignored.) 

41""" 

42) 

43 

44 

45def _doBuild(ctx, **kwargs): 

46 # The pipeline actions (task, delete, config, config_file, and instrument) 

47 # must be handled in the order they appear on the command line, but the CLI 

48 # specification gives them all different option names. So, instead of using 

49 # the individual action options as they appear in kwargs (because 

50 # invocation order can't be known), we capture the CLI arguments by 

51 # overriding `click.Command.parse_args` and save them in the Context's 

52 # `obj` parameter. We use `makePipelineActions` to create a list of 

53 # pipeline actions from the CLI arguments and pass that list to the script 

54 # function using the `pipeline_actions` kwarg name, and remove the action 

55 # options from kwargs. 

56 for pipelineAction in ( 

57 ctrlMpExecOpts.task_option.name(), 

58 ctrlMpExecOpts.delete_option.name(), 

59 config_option.name(), 

60 config_file_option.name(), 

61 obsBaseOpts.instrument_option.name(), 

62 ): 

63 kwargs.pop(pipelineAction) 

64 kwargs["pipeline_actions"] = makePipelineActions(MWCtxObj.getFrom(ctx).args) 

65 return script.build(**kwargs) 

66 

67 

68@click.command(cls=PipetaskCommand, epilog=epilog, short_help="Build pipeline definition.") 

69@click.pass_context 

70@ctrlMpExecOpts.show_option() 

71@ctrlMpExecOpts.pipeline_build_options() 

72@option_section(sectionText="") 

73@options_file_option() 

74@catch_and_exit 

75def build(ctx, **kwargs): 

76 """Build and optionally save pipeline definition. 

77 

78 This does not require input data to be specified. 

79 """ 

80 _doBuild(ctx, **kwargs) 

81 

82 

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() 

91@catch_and_exit 

92def qgraph(ctx, **kwargs): 

93 """Build and optionally save quantum graph.""" 

94 pipeline = _doBuild(ctx, **kwargs) 

95 script.qgraph(pipelineObj=pipeline, **kwargs) 

96 

97 

98@click.command(cls=PipetaskCommand, epilog=epilog) 

99@ctrlMpExecOpts.run_options() 

100@catch_and_exit 

101def run(ctx, **kwargs): 

102 """Build and execute pipeline and quantum graph.""" 

103 pipeline = _doBuild(ctx, **kwargs) 

104 qgraph = script.qgraph(pipelineObj=pipeline, **kwargs) 

105 script.run(qgraphObj=qgraph, **kwargs)