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 (MWCtxObj, 

28 catch_and_exit, 

29 option_section, 

30 unwrap) 

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

32from .. import opt as ctrlMpExecOpts 

33from .. import script 

34from ..utils import makePipelineActions, PipetaskCommand 

35 

36 

37epilog = unwrap("""Notes: 

38 

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

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

41 

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

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

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

45ignored.) 

46""") 

47 

48 

49def _doBuild(ctx, **kwargs): 

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

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

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

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

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

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

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

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

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

59 # options from kwargs. 

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

61 config_option.name(), config_file_option.name(), 

62 obsBaseOpts.instrument_option.name()): 

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 """ 

95 pipeline = _doBuild(ctx, **kwargs) 

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

97 

98 

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

100@ctrlMpExecOpts.run_options() 

101@catch_and_exit 

102def run(ctx, **kwargs): 

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

104 """ 

105 pipeline = _doBuild(ctx, **kwargs) 

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

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