| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 from __future__ import absolute_import | 5 from __future__ import absolute_import |
| 6 import contextlib | 6 import contextlib |
| 7 import collections | 7 import collections |
| 8 import keyword | 8 import keyword |
| 9 import re | 9 import re |
| 10 import types | 10 import types |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ) | 58 ) |
| 59 | 59 |
| 60 def _render_to_dict(self): | 60 def _render_to_dict(self): |
| 61 d = dict((k, v) for k, v in self._asdict().iteritems() if v) | 61 d = dict((k, v) for k, v in self._asdict().iteritems() if v) |
| 62 if d['critical']: | 62 if d['critical']: |
| 63 d.pop('critical') | 63 d.pop('critical') |
| 64 return d | 64 return d |
| 65 | 65 |
| 66 | 66 |
| 67 _StepConfig = collections.namedtuple('_StepConfig', | 67 _StepConfig = collections.namedtuple('_StepConfig', |
| 68 ('name', 'cmd', 'cwd', 'env', 'allow_subannotations', 'trigger_specs', | 68 ('name', 'base_name', 'cmd', 'cwd', 'env', 'allow_subannotations', |
| 69 'timeout', 'infra_step', 'stdout', 'stderr', 'stdin', 'ok_ret', | 69 'trigger_specs', 'timeout', 'infra_step', 'stdout', 'stderr', 'stdin', |
| 70 'step_test_data', 'nest_level')) | 70 'ok_ret', 'step_test_data', 'nest_level')) |
| 71 | 71 |
| 72 class StepConfig(_StepConfig): | 72 class StepConfig(_StepConfig): |
| 73 """ | 73 """ |
| 74 StepConfig is the representation of a raw step as the recipe_engine sees it. | 74 StepConfig is the representation of a raw step as the recipe_engine sees it. |
| 75 You should use the standard 'step' recipe module, which will construct and | 75 You should use the standard 'step' recipe module, which will construct and |
| 76 pass this data to the engine for you, instead. The only reason why you would | 76 pass this data to the engine for you, instead. The only reason why you would |
| 77 need to worry about this object is if you're modifying the step module itself. | 77 need to worry about this object is if you're modifying the step module itself. |
| 78 | 78 |
| 79 The optional "env" parameter provides optional overrides for environment | 79 The optional "env" parameter provides optional overrides for environment |
| 80 variables. Each value is % formatted with the entire existing os.environ. A | 80 variables. Each value is % formatted with the entire existing os.environ. A |
| 81 value of `None` will remove that envvar from the environ. e.g. | 81 value of `None` will remove that envvar from the environ. e.g. |
| 82 | 82 |
| 83 { | 83 { |
| 84 "envvar": "%(envvar)s;%(envvar2)s;extra", | 84 "envvar": "%(envvar)s;%(envvar2)s;extra", |
| 85 "delete_this": None, | 85 "delete_this": None, |
| 86 "static_value": "something", | 86 "static_value": "something", |
| 87 } | 87 } |
| 88 """ | 88 """ |
| 89 | 89 |
| 90 _RENDER_WHITELIST=frozenset(( | 90 _RENDER_WHITELIST=frozenset(( |
| 91 'cmd', | 91 'cmd', |
| 92 )) | 92 )) |
| 93 | 93 |
| 94 _RENDER_BLACKLIST=frozenset(( | 94 _RENDER_BLACKLIST=frozenset(( |
| 95 'base_name', |
| 95 'nest_level', | 96 'nest_level', |
| 96 'ok_ret', | 97 'ok_ret', |
| 97 'infra_step', | 98 'infra_step', |
| 98 'step_test_data', | 99 'step_test_data', |
| 99 )) | 100 )) |
| 100 | 101 |
| 101 @classmethod | 102 @classmethod |
| 102 def create(cls, name, cmd=None, cwd=None, env=None, | 103 def create(cls, name, base_name=None, cmd=None, cwd=None, env=None, |
| 103 allow_subannotations=None, trigger_specs=None, timeout=None, | 104 allow_subannotations=None, trigger_specs=None, timeout=None, |
| 104 infra_step=None, stdout=None, stderr=None, stdin=None, | 105 infra_step=None, stdout=None, stderr=None, stdin=None, |
| 105 ok_ret=None, step_test_data=None, step_nest_level=None): | 106 ok_ret=None, step_test_data=None, step_nest_level=None): |
| 106 """ | 107 """ |
| 107 Initializes a new StepConfig step API dictionary. | 108 Initializes a new StepConfig step API dictionary. |
| 108 | 109 |
| 109 Args: | 110 Args: |
| 110 name (str): name of the step, will appear in buildbots waterfall | 111 name (str): name of the step, will appear in buildbots waterfall |
| 112 base_name (str): the base name of the step. If the step has a derived |
| 113 name (e.g., nested may be concatenated with its parent), this is the |
| 114 name component of just this step. If None, this will be set to "name". |
| 111 cmd: command to run. Acceptable types: str, Path, Placeholder, or None. | 115 cmd: command to run. Acceptable types: str, Path, Placeholder, or None. |
| 112 cwd (str or None): absolute path to working directory for the command | 116 cwd (str or None): absolute path to working directory for the command |
| 113 env (dict): overrides for environment variables, described above. | 117 env (dict): overrides for environment variables, described above. |
| 114 allow_subannotations (bool): if True, lets the step emit its own | 118 allow_subannotations (bool): if True, lets the step emit its own |
| 115 annotations. NOTE: Enabling this can cause some buggy behavior. Please | 119 annotations. NOTE: Enabling this can cause some buggy behavior. Please |
| 116 strongly consider using step_result.presentation instead. If you have | 120 strongly consider using step_result.presentation instead. If you have |
| 117 questions, please contact infra-dev@chromium.org. | 121 questions, please contact infra-dev@chromium.org. |
| 118 trigger_specs: a list of trigger specifications, see also _trigger_builds. | 122 trigger_specs: a list of trigger specifications, see also _trigger_builds. |
| 119 timeout: if not None, a datetime.timedelta for the step timeout. | 123 timeout: if not None, a datetime.timedelta for the step timeout. |
| 120 infra_step: if True, this is an infrastructure step. Failures will raise | 124 infra_step: if True, this is an infrastructure step. Failures will raise |
| 121 InfraFailure instead of StepFailure. | 125 InfraFailure instead of StepFailure. |
| 122 stdout: Placeholder to put step stdout into. If used, stdout won't appear | 126 stdout: Placeholder to put step stdout into. If used, stdout won't appear |
| 123 in annotator's stdout (and |allow_subannotations| is ignored). | 127 in annotator's stdout (and |allow_subannotations| is ignored). |
| 124 stderr: Placeholder to put step stderr into. If used, stderr won't appear | 128 stderr: Placeholder to put step stderr into. If used, stderr won't appear |
| 125 in annotator's stderr. | 129 in annotator's stderr. |
| 126 stdin: Placeholder to read step stdin from. | 130 stdin: Placeholder to read step stdin from. |
| 127 ok_ret (iter): set of return codes allowed. If the step process returns | 131 ok_ret (iter): set of return codes allowed. If the step process returns |
| 128 something not on this list, it will raise a StepFailure (or | 132 something not on this list, it will raise a StepFailure (or |
| 129 InfraFailure if infra_step is True). If omitted, {0} will be used. | 133 InfraFailure if infra_step is True). If omitted, {0} will be used. |
| 130 step_test_data (func -> recipe_test_api.StepTestData): A factory which | 134 step_test_data (func -> recipe_test_api.StepTestData): A factory which |
| 131 returns a StepTestData object that will be used as the default test | 135 returns a StepTestData object that will be used as the default test |
| 132 data for this step. The recipe author can override/augment this object | 136 data for this step. The recipe author can override/augment this object |
| 133 in the GenTests function. | 137 in the GenTests function. |
| 134 step_nest_level (int): the step's nesting level. | 138 step_nest_level (int): the step's nesting level. |
| 135 """ | 139 """ |
| 136 return cls( | 140 return cls( |
| 137 name=name, | 141 name=name, |
| 142 base_name=(base_name or name), |
| 138 cmd=cmd, | 143 cmd=cmd, |
| 139 cwd=cwd, | 144 cwd=cwd, |
| 140 env=env, | 145 env=env, |
| 141 allow_subannotations=bool(allow_subannotations), | 146 allow_subannotations=bool(allow_subannotations), |
| 142 trigger_specs=[TriggerSpec._create(**trig) | 147 trigger_specs=[TriggerSpec._create(**trig) |
| 143 for trig in (trigger_specs or ())], | 148 for trig in (trigger_specs or ())], |
| 144 timeout=timeout, | 149 timeout=timeout, |
| 145 infra_step=bool(infra_step), | 150 infra_step=bool(infra_step), |
| 146 stdout=stdout, | 151 stdout=stdout, |
| 147 stderr=stderr, | 152 stderr=stderr, |
| (...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 """ | 811 """ |
| 807 Gets the BoundProperty version of this Property. Requires a name. | 812 Gets the BoundProperty version of this Property. Requires a name. |
| 808 """ | 813 """ |
| 809 return BoundProperty( | 814 return BoundProperty( |
| 810 self._default, self.help, self.kind, name, property_type, module, | 815 self._default, self.help, self.kind, name, property_type, module, |
| 811 self.param_name) | 816 self.param_name) |
| 812 | 817 |
| 813 class UndefinedPropertyException(TypeError): | 818 class UndefinedPropertyException(TypeError): |
| 814 pass | 819 pass |
| 815 | 820 |
| OLD | NEW |