Chromium Code Reviews| 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 bisect | 6 import bisect |
| 7 import collections | 7 import collections |
| 8 import contextlib | 8 import contextlib |
| 9 import copy | 9 import copy |
| 10 import json | 10 import json |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 return copy.deepcopy(self._engine.properties) | 168 return copy.deepcopy(self._engine.properties) |
| 169 | 169 |
| 170 | 170 |
| 171 class StepClient(object): | 171 class StepClient(object): |
| 172 """A recipe engine client representing step running and introspection.""" | 172 """A recipe engine client representing step running and introspection.""" |
| 173 | 173 |
| 174 IDENT = 'step' | 174 IDENT = 'step' |
| 175 | 175 |
| 176 | 176 |
| 177 class StepConfig(collections.namedtuple('_StepConfig', ( | 177 class StepConfig(collections.namedtuple('_StepConfig', ( |
| 178 'name', 'base_name', 'cmd', 'cwd', 'env', 'env_prefixes', | 178 'name', 'base_name', 'cmd', 'cwd', 'env', 'env_prefixes', 'luci_context', |
| 179 'allow_subannotations', 'trigger_specs', 'timeout', 'infra_step', | 179 'allow_subannotations', 'trigger_specs', 'timeout', 'infra_step', |
| 180 'stdout', 'stderr', 'stdin', 'ok_ret', 'step_test_data', 'nest_level'))): | 180 'stdout', 'stderr', 'stdin', 'ok_ret', 'step_test_data', 'nest_level'))): |
| 181 | 181 |
| 182 """ | 182 """ |
| 183 StepConfig is the representation of a raw step as the recipe_engine sees it. | 183 StepConfig is the representation of a raw step as the recipe_engine sees it. |
| 184 You should use the standard 'step' recipe module, which will construct and | 184 You should use the standard 'step' recipe module, which will construct and |
| 185 pass this data to the engine for you, instead. The only reason why you would | 185 pass this data to the engine for you, instead. The only reason why you would |
| 186 need to worry about this object is if you're modifying the step module | 186 need to worry about this object is if you're modifying the step module |
| 187 itself. | 187 itself. |
| 188 | 188 |
| 189 Fields: | 189 Fields: |
| 190 name (str): name of the step, will appear in buildbots waterfall | 190 name (str): name of the step, will appear in buildbots waterfall |
| 191 base_name (str): the base name of the step. If the step has a derived | 191 base_name (str): the base name of the step. If the step has a derived |
| 192 name (e.g., nested may be concatenated with its parent), this is the | 192 name (e.g., nested may be concatenated with its parent), this is the |
| 193 name component of just this step. If None, this will be set to "name". | 193 name component of just this step. If None, this will be set to "name". |
| 194 cmd: command to run. Acceptable types: str, Path, Placeholder, or None. | 194 cmd: command to run. Acceptable types: str, Path, Placeholder, or None. |
| 195 cwd (str or None): absolute path to working directory for the command | 195 cwd (str or None): absolute path to working directory for the command |
| 196 env (dict): overrides for environment variables, described above. | 196 env (dict): overrides for environment variables, described above. |
| 197 env_prefixes (dict): environment prefix variables, mapping environment | 197 env_prefixes (dict): environment prefix variables, mapping environment |
| 198 variable names to EnvPrefix values. | 198 variable names to EnvPrefix values. |
| 199 luci_context (dict): overrides for the LUCI_CONTEXT dict. | |
| 199 allow_subannotations (bool): if True, lets the step emit its own | 200 allow_subannotations (bool): if True, lets the step emit its own |
| 200 annotations. NOTE: Enabling this can cause some buggy behavior. Please | 201 annotations. NOTE: Enabling this can cause some buggy behavior. Please |
| 201 strongly consider using step_result.presentation instead. If you have | 202 strongly consider using step_result.presentation instead. If you have |
| 202 questions, please contact infra-dev@chromium.org. | 203 questions, please contact infra-dev@chromium.org. |
| 203 trigger_specs: a list of trigger specifications, see also _trigger_builds. | 204 trigger_specs: a list of trigger specifications, see also _trigger_builds. |
| 204 timeout: if not None, a datetime.timedelta for the step timeout. | 205 timeout: if not None, a datetime.timedelta for the step timeout. |
| 205 infra_step: if True, this is an infrastructure step. Failures will raise | 206 infra_step: if True, this is an infrastructure step. Failures will raise |
| 206 InfraFailure instead of StepFailure. | 207 InfraFailure instead of StepFailure. |
| 207 stdout: Placeholder to put step stdout into. If used, stdout won't appear | 208 stdout: Placeholder to put step stdout into. If used, stdout won't appear |
| 208 in annotator's stdout (and |allow_subannotations| is ignored). | 209 in annotator's stdout (and |allow_subannotations| is ignored). |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 for k, v in self.prefixes.iteritems()} | 260 for k, v in self.prefixes.iteritems()} |
| 260 return pprint.pformat(rendered, width=1024) | 261 return pprint.pformat(rendered, width=1024) |
| 261 | 262 |
| 262 | 263 |
| 263 _RENDER_WHITELIST=frozenset(( | 264 _RENDER_WHITELIST=frozenset(( |
| 264 'cmd', | 265 'cmd', |
| 265 )) | 266 )) |
| 266 | 267 |
| 267 _RENDER_BLACKLIST=frozenset(( | 268 _RENDER_BLACKLIST=frozenset(( |
| 268 'base_name', | 269 'base_name', |
| 270 'luci_context', # it's ambient and used only for advanced stuff | |
|
iannucci
2017/08/04 18:55:50
This blacklist is used for excluding the entry fro
| |
| 269 'nest_level', | 271 'nest_level', |
| 270 'ok_ret', | 272 'ok_ret', |
| 271 'step_test_data', | 273 'step_test_data', |
| 272 )) | 274 )) |
| 273 | 275 |
| 274 def __new__(cls, **kwargs): | 276 def __new__(cls, **kwargs): |
| 275 for field in cls._fields: | 277 for field in cls._fields: |
| 276 kwargs.setdefault(field, None) | 278 kwargs.setdefault(field, None) |
| 277 sc = super(StepClient.StepConfig, cls).__new__(cls, **kwargs) | 279 sc = super(StepClient.StepConfig, cls).__new__(cls, **kwargs) |
| 278 | 280 |
| 279 return sc._replace( | 281 return sc._replace( |
| 280 cmd=[(x if isinstance(x, Placeholder) else str(x)) | 282 cmd=[(x if isinstance(x, Placeholder) else str(x)) |
| 281 for x in (sc.cmd or ())], | 283 for x in (sc.cmd or ())], |
| 282 cwd=(str(sc.cwd) if sc.cwd else (None)), | 284 cwd=(str(sc.cwd) if sc.cwd else (None)), |
| 283 env=sc.env or {}, | 285 env=sc.env or {}, |
| 284 env_prefixes=sc.env_prefixes or cls.EnvPrefix.empty(), | 286 env_prefixes=sc.env_prefixes or cls.EnvPrefix.empty(), |
| 287 luci_context=sc.luci_context or {}, | |
| 285 base_name=sc.base_name or sc.name, | 288 base_name=sc.base_name or sc.name, |
| 286 allow_subannotations=bool(sc.allow_subannotations), | 289 allow_subannotations=bool(sc.allow_subannotations), |
| 287 trigger_specs=sc.trigger_specs or (), | 290 trigger_specs=sc.trigger_specs or (), |
| 288 infra_step=bool(sc.infra_step), | 291 infra_step=bool(sc.infra_step), |
| 289 ok_ret=frozenset(sc.ok_ret or (0,)), | 292 ok_ret=frozenset(sc.ok_ret or (0,)), |
| 290 nest_level=int(sc.nest_level or 0), | 293 nest_level=int(sc.nest_level or 0), |
| 291 ) | 294 ) |
| 292 | 295 |
| 293 def render_to_dict(self): | 296 def render_to_dict(self): |
| 294 sc = self._replace( | 297 sc = self._replace( |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 def bind(self, name, property_type, full_decl_name): | 1097 def bind(self, name, property_type, full_decl_name): |
| 1095 """ | 1098 """ |
| 1096 Gets the BoundProperty version of this Property. Requires a name. | 1099 Gets the BoundProperty version of this Property. Requires a name. |
| 1097 """ | 1100 """ |
| 1098 return BoundProperty( | 1101 return BoundProperty( |
| 1099 self._default, self.help, self.kind, name, property_type, full_decl_name, | 1102 self._default, self.help, self.kind, name, property_type, full_decl_name, |
| 1100 self.param_name) | 1103 self.param_name) |
| 1101 | 1104 |
| 1102 class UndefinedPropertyException(TypeError): | 1105 class UndefinedPropertyException(TypeError): |
| 1103 pass | 1106 pass |
| OLD | NEW |