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 

23import copy 

24 

25from lsst.daf.butler.cli.opt import (config_file_option, 

26 config_option, 

27 log_level_option) 

28from lsst.daf.butler.cli.utils import cli_handle_exception 

29from lsst.obs.base.cli.opt import instrument_parameter 

30from ..opt import (delete_option, 

31 order_pipeline_option, 

32 pipeline_dot_option, 

33 pipeline_option, 

34 save_pipeline_option, 

35 show_option, 

36 task_option) 

37from .. import script 

38from ..utils import makePipelineActions 

39 

40 

41instrumentOptionHelp = ("Add an instrument which will be used to load config overrides when defining a " 

42 "pipeline. This must be the fully qualified class name.") 

43 

44 

45class PipetaskCommand(click.Command): 

46 def parse_args(self, ctx, args): 

47 ctx.obj = copy.copy(args) 

48 super().parse_args(ctx, args) 

49 

50 

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

52@click.pass_context 

53@pipeline_option() 

54@task_option(multiple=True) 

55@delete_option(metavar="LABEL", multiple=True) 

56@config_option(metavar="LABEL:NAME=VALUE", multiple=True) 

57@config_file_option(help="Configuration override file(s), applies to a task with a given label.", 

58 metavar="LABEL:FILE", 

59 multiple=True) 

60@order_pipeline_option() 

61@save_pipeline_option() 

62@pipeline_dot_option() 

63@instrument_parameter(help=instrumentOptionHelp, metavar="instrument", multiple=True) 

64@show_option(multiple=True) 

65@log_level_option(defaultValue=None) 

66def build(ctx, *args, **kwargs): 

67 """Build and optionally save pipeline definition. 

68 

69 This does not require input data to be specified. 

70 """ 

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

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

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

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

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

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

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

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

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

80 # options from kwargs. 

81 for pipelineAction in (task_option.optionKey, delete_option.optionKey, config_option.optionKey, 

82 config_file_option.optionKey, instrument_parameter.optionKey): 

83 kwargs.pop(pipelineAction) 

84 kwargs['pipeline_actions'] = makePipelineActions(ctx.obj) 

85 cli_handle_exception(script.build, *args, **kwargs) 

86 

87 

88@click.command(cls=PipetaskCommand) 

89def qgraph(*args, **kwargs): 

90 """Not implemented. 

91 

92 Build and optionally save pipeline and quantum graph. 

93 """ 

94 print("Not implemented.") 

95 

96 

97@click.command(cls=PipetaskCommand) 

98def run(*args, **kwargs): 

99 """Not implemented. 

100 

101 Build and execute pipeline and quantum graph. 

102 """ 

103 print("Not implemented.")