Hide keyboard shortcuts

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

21 

22import click 

23 

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 MWCommand, 

29 MWCtxObj, 

30 option_section, 

31 unwrap) 

32import lsst.daf.butler.cli.opt as dafButlerOpts 

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

34from .. import opt as ctrlMpExecOpts 

35from .. import script 

36from ..utils import makePipelineActions 

37 

38 

39forwardEpilog = unwrap("""Options marked with (f) are forwarded to the next subcommand if multiple subcommands 

40 are chained in the same command execution. Previous values may be overridden by passing new 

41 option values into the next subcommand.""") 

42 

43buildEpilog = unwrap("""Notes: 

44 

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

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

47 

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

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

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

51ignored.) 

52""") 

53 

54qgraphEpilog = forwardEpilog 

55 

56runEpilog = forwardEpilog 

57 

58 

59def _doBuild(ctx, **kwargs): 

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

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

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

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

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

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

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

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

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

69 # options from kwargs. 

70 for pipelineAction in (ctrlMpExecOpts.task_option.name(), ctrlMpExecOpts.delete_option.name(), 

71 config_option.name(), config_file_option.name(), 

72 obsBaseOpts.instrument_option.name()): 

73 kwargs.pop(pipelineAction) 

74 kwargs['pipeline_actions'] = makePipelineActions(MWCtxObj.getFrom(ctx).args) 

75 return cli_handle_exception(script.build, **kwargs) 

76 

77 

78@click.command(cls=MWCommand, epilog=buildEpilog, short_help="Build pipeline definition.") 

79@click.pass_context 

80@dafButlerOpts.log_level_option() 

81@ctrlMpExecOpts.show_option() 

82@ctrlMpExecOpts.pipeline_build_options() 

83@option_section(sectionText="") 

84@options_file_option() 

85def build(ctx, **kwargs): 

86 """Build and optionally save pipeline definition. 

87 

88 This does not require input data to be specified. 

89 """ 

90 _doBuild(ctx, **kwargs) 

91 

92 

93@click.command(cls=MWCommand, epilog=qgraphEpilog) 

94@click.pass_context 

95@dafButlerOpts.log_level_option() 

96@ctrlMpExecOpts.show_option() 

97@ctrlMpExecOpts.pipeline_build_options() 

98@ctrlMpExecOpts.qgraph_options() 

99@ctrlMpExecOpts.butler_options() 

100@option_section(sectionText="") 

101@options_file_option() 

102def qgraph(ctx, **kwargs): 

103 """Build and optionally save quantum graph. 

104 """ 

105 pipeline = _doBuild(ctx, **kwargs) 

106 cli_handle_exception(script.qgraph, pipelineObj=pipeline, **kwargs) 

107 

108 

109@click.command(cls=MWCommand, epilog=runEpilog) 

110@click.pass_context 

111@dafButlerOpts.log_level_option() 

112@ctrlMpExecOpts.debug_option() 

113@ctrlMpExecOpts.show_option() 

114@ctrlMpExecOpts.pipeline_build_options() 

115@ctrlMpExecOpts.qgraph_options() 

116@ctrlMpExecOpts.butler_options() 

117@ctrlMpExecOpts.execution_options() 

118@ctrlMpExecOpts.meta_info_options() 

119@option_section(sectionText="") 

120@options_file_option() 

121def run(ctx, **kwargs): 

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

123 """ 

124 pipeline = _doBuild(ctx, **kwargs) 

125 qgraph = cli_handle_exception(script.qgraph, pipelineObj=pipeline, **kwargs) 

126 cli_handle_exception(script.run, qgraphObj=qgraph, **kwargs)