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

29 unwrap) 

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

31from .. import opt as ctrlMpExecOpts 

32from .. import script 

33from ..utils import makePipelineActions, PipetaskCommand 

34 

35 

36epilog = unwrap("""Notes: 

37 

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

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

40 

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

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

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

44ignored.) 

45""") 

46 

47 

48def _doBuild(ctx, **kwargs): 

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

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

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

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

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

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

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

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

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

58 # options from kwargs. 

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

60 config_option.name(), config_file_option.name(), 

61 obsBaseOpts.instrument_option.name()): 

62 kwargs.pop(pipelineAction) 

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

64 return script.build(**kwargs) 

65 

66 

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

68@click.pass_context 

69@ctrlMpExecOpts.show_option() 

70@ctrlMpExecOpts.pipeline_build_options() 

71@option_section(sectionText="") 

72@options_file_option() 

73def build(ctx, **kwargs): 

74 """Build and optionally save pipeline definition. 

75 

76 This does not require input data to be specified. 

77 """ 

78 _doBuild(ctx, **kwargs) 

79 

80 

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

82@click.pass_context 

83@ctrlMpExecOpts.show_option() 

84@ctrlMpExecOpts.pipeline_build_options() 

85@ctrlMpExecOpts.qgraph_options() 

86@ctrlMpExecOpts.butler_options() 

87@option_section(sectionText="") 

88@options_file_option() 

89def qgraph(ctx, **kwargs): 

90 """Build and optionally save quantum graph. 

91 """ 

92 pipeline = _doBuild(ctx, **kwargs) 

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

94 

95 

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

97@ctrlMpExecOpts.run_options() 

98def run(ctx, **kwargs): 

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

100 """ 

101 pipeline = _doBuild(ctx, **kwargs) 

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

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