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 

22from types import SimpleNamespace 

23 

24from lsst.daf.butler.cli.cliLog import CliLog 

25from ... import CmdLineFwk 

26from ...cmdLineParser import _PipelineAction 

27 

28 

29def build(order_pipeline, pipeline, pipeline_actions, pipeline_dot, save_pipeline, show, log_level, **kwargs): 

30 """Implements the command line interface `pipetask build` subcommand, 

31 should only be called by command line tools and unit test code that tests 

32 this function. 

33 

34 Build and optionally save pipeline definition. 

35 

36 Returns the pipeline instance that was built, for testing and for using 

37 this function with other script functions. 

38 

39 Parameters 

40 ---------- 

41 order_pipeline : `bool` 

42 If true, order tasks in pipeline based on their data dependencies, 

43 ordering is performed as last step before saving or executing pipeline. 

44 pipeline_actions : `list` [`PipelineAction`]] or `PipelineAction` 

45 A list of pipeline actions in the order they should be executed. 

46 pipeline_dot : `str` 

47 Path location for storing GraphViz DOT representation of a pipeline. 

48 pipeline : `str` 

49 Path location of a pipeline definition file in YAML format. 

50 save_pipeline : `str` 

51 Path location for storing resulting pipeline definition in YAML format. 

52 show : `list` [`str`] 

53 Descriptions of what to dump to stdout. 

54 log_level : `list` of `tuple` 

55 Per-component logging levels, each item in the list is a tuple 

56 (component, level), `component` is a logger name or an empty string 

57 or `None` for root logger, `level` is a logging level name, one of 

58 CRITICAL, ERROR, WARNING, INFO, DEBUG (case insensitive). 

59 kwargs : `dict` [`str`, `str`] 

60 Ignored; click commands may accept options for more than one script 

61 function and pass all the option kwargs to each of the script functions 

62 which ingore these unused kwargs. 

63 

64 Returns 

65 ------- 

66 pipeline : `lsst.pipe.base.Pipeline` 

67 The pipeline instance that was built. 

68 

69 Raises 

70 ------ 

71 Exception 

72 Raised if there is a failure building the pipeline. 

73 """ 

74 # If pipeline_actions is a single instance, not a list, then put it in 

75 # a list. _PipelineAction is a namedtuple, so we can't use 

76 # `lsst.daf.butler.core.utils.iterable` because a namedtuple *is* iterable, 

77 # but we need a list of _PipelineAction. 

78 if isinstance(pipeline_actions, _PipelineAction): 

79 pipeline_actions = (pipeline_actions,) 

80 

81 if log_level is not None: 

82 CliLog.setLogLevels(log_level) 

83 

84 args = SimpleNamespace(pipeline=pipeline, 

85 pipeline_actions=pipeline_actions, 

86 pipeline_dot=pipeline_dot, 

87 save_pipeline=save_pipeline) 

88 

89 f = CmdLineFwk() 

90 

91 # Will raise an exception if it fails to build the pipeline. 

92 pipeline = f.makePipeline(args) 

93 

94 args = SimpleNamespace(show=show) 

95 f.showInfo(args, pipeline) 

96 

97 return pipeline