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

29 MWCommand, 

30 MWCtxObj, 

31 option_section, 

32 unwrap) 

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

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

35from .. import opt as ctrlMpExecOpts 

36from .. import script 

37from ..utils import makePipelineActions 

38 

39 

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

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

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

43 

44buildEpilog = unwrap("""Notes: 

45 

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

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

48 

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

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

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

52ignored.) 

53""") 

54 

55qgraphEpilog = forwardEpilog 

56 

57runEpilog = forwardEpilog 

58 

59 

60def _doBuild(ctx, **kwargs): 

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

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

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

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

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

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

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

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

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

70 # options from kwargs. 

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

72 config_option.name(), config_file_option.name(), 

73 obsBaseOpts.instrument_option.name()): 

74 kwargs.pop(pipelineAction) 

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

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

77 

78 

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

80@click.pass_context 

81@dafButlerOpts.log_level_option() 

82@ctrlMpExecOpts.show_option() 

83@ctrlMpExecOpts.pipeline_build_options() 

84@option_section(sectionText="") 

85@options_file_option() 

86def build(ctx, **kwargs): 

87 """Build and optionally save pipeline definition. 

88 

89 This does not require input data to be specified. 

90 """ 

91 _doBuild(ctx, **kwargs) 

92 

93 

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

95@click.pass_context 

96@dafButlerOpts.log_level_option() 

97@ctrlMpExecOpts.show_option() 

98@ctrlMpExecOpts.pipeline_build_options() 

99@ctrlMpExecOpts.qgraph_options() 

100@ctrlMpExecOpts.butler_options() 

101@option_section(sectionText="") 

102@options_file_option() 

103def qgraph(ctx, **kwargs): 

104 """Build and optionally save quantum graph. 

105 """ 

106 pipeline = _doBuild(ctx, **kwargs) 

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

108 

109 

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

111@click.pass_context 

112@dafButlerOpts.log_level_option() 

113@ctrlMpExecOpts.debug_option() 

114@ctrlMpExecOpts.show_option() 

115@ctrlMpExecOpts.pipeline_build_options() 

116@ctrlMpExecOpts.qgraph_options() 

117@ctrlMpExecOpts.butler_options() 

118@ctrlMpExecOpts.execution_options() 

119@ctrlMpExecOpts.meta_info_options() 

120@option_section(sectionText="") 

121@options_file_option() 

122# --call-mocker is for use with test code, it is not intended for CLI or other 

123# non-testing use. It allows this command function to be executed 

124# programatically and have it call Mocker with its kwargs, which can the be 

125# gotten from Mocker later. At some point, ctrl_mpexec should stop passing 

126# around a SimpleNamespace of arguments, which would make this workaround 

127# unnecessary. 

128@click.option("--call-mocker", 

129 is_flag=True, 

130 hidden=True) # do not show this option in the help menu. 

131def run(ctx, **kwargs): 

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

133 """ 

134 if kwargs["call_mocker"]: 134 ↛ 137line 134 didn't jump to line 137, because the condition on line 134 was never false

135 Mocker(**kwargs) 

136 return 

137 pipeline = _doBuild(ctx, **kwargs) 

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

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