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) 

26from lsst.daf.butler.cli.utils import (cli_handle_exception, 

27 MWCommand, 

28 MWCtxObj, 

29 option_section, 

30 unwrap) 

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

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

33from .. import opt as ctrlMpExecOpts 

34from .. import script 

35from ..utils import makePipelineActions 

36 

37 

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

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

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

41 

42buildEpilog = unwrap(f"""Notes: 

43 

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

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

46 

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

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

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

50ignored.) 

51""") 

52 

53qgraphEpilog = forwardEpilog 

54 

55runEpilog = forwardEpilog 

56 

57 

58def _doBuild(ctx, **kwargs): 

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

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

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

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

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

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

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

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

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

68 # options from kwargs. 

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

70 config_option.name(), config_file_option.name(), 

71 obsBaseOpts.instrument_option.name()): 

72 kwargs.pop(pipelineAction) 

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

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

75 

76 

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

78@click.pass_context 

79@dafButlerOpts.log_level_option() 

80@ctrlMpExecOpts.show_option() 

81@ctrlMpExecOpts.pipeline_build_options() 

82@option_section(sectionText="") 

83def build(ctx, **kwargs): 

84 """Build and optionally save pipeline definition. 

85 

86 This does not require input data to be specified. 

87 """ 

88 _doBuild(ctx, **kwargs) 

89 

90 

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

92@click.pass_context 

93@dafButlerOpts.log_level_option() 

94@ctrlMpExecOpts.show_option() 

95@ctrlMpExecOpts.pipeline_build_options() 

96@ctrlMpExecOpts.qgraph_options() 

97@ctrlMpExecOpts.butler_options() 

98@option_section(sectionText="") 

99def qgraph(ctx, **kwargs): 

100 """Build and optionally save quantum graph. 

101 """ 

102 pipeline = _doBuild(ctx, **kwargs) 

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

104 

105 

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

107@click.pass_context 

108@dafButlerOpts.log_level_option() 

109@ctrlMpExecOpts.debug_option() 

110@ctrlMpExecOpts.show_option() 

111@ctrlMpExecOpts.pipeline_build_options() 

112@ctrlMpExecOpts.qgraph_options() 

113@ctrlMpExecOpts.butler_options() 

114@ctrlMpExecOpts.execution_options() 

115@ctrlMpExecOpts.meta_info_options() 

116@option_section(sectionText="") 

117def run(ctx, **kwargs): 

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

119 """ 

120 pipeline = _doBuild(ctx, **kwargs) 

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

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