Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: recipe_engine/recipe_api.py

Issue 2253943003: Formally define step config, pass to stream. (Closed) Base URL: https://github.com/luci/recipes-py@nest-single-event
Patch Set: Rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipe_engine/run.py » ('j') | recipe_engine/step_runner.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 keyword 8 import keyword
8 import re 9 import re
9 import types 10 import types
10 11
11 from functools import wraps 12 from functools import wraps
12 13
13 from .recipe_test_api import DisabledTestData, ModuleTestData 14 from .recipe_test_api import DisabledTestData, ModuleTestData
14 from .config import Single 15 from .config import Single
15 16
16 from .util import ModuleInjectionSite 17 from .util import ModuleInjectionSite
17 18
18 from . import field_composer 19 from . import field_composer
19 20
20 21
22 _StepConfig = collections.namedtuple('StepConfig',
iannucci 2016/09/12 19:41:07 I would name this inner class _StepConfig too. Oth
23 ('name', 'cmd', 'cwd', 'env', 'allow_subannotations', 'trigger_specs',
24 'timeout', 'infra_step', 'stdout', 'stderr', 'stdin', 'ok_ret',
25 'step_test_data', 'nest_level'))
26
27 class StepConfig(_StepConfig):
28 """
iannucci 2016/09/12 19:41:07 StepConfig is the representation of a raw step as
29 StepConfig parameters:
30 name: name of the step, will appear in buildbots waterfall
iannucci 2016/09/12 19:41:07 let's add types to these, e.g. name (str): ...
31 cmd: command to run, list of one or more strings
iannucci 2016/09/12 19:41:07 cmd (list): command to run. Acceptable types: str,
32 cwd: absolute path to working directory for the command
iannucci 2016/09/12 19:41:07 cwd (Path): ...
33 env: dict with overrides for environment variables
iannucci 2016/09/12 19:41:07 env (dict): overrides for environment variables. E
34 allow_subannotations: if True, lets the step emit its own annotations
iannucci 2016/09/12 19:41:07 NOTE: Enabling this can cause some buggy behavior.
35 trigger_specs: a list of trigger specifications, see also _trigger_builds.
iannucci 2016/09/12 19:41:07 example schema? Actually... maybe another named tu
36 timeout: if not None, a datetime.timedelta for the step timeout.
37 infra_step: if True, this is an infrastructure step.
iannucci 2016/09/12 19:41:07 ...... will raise InfraFailure instead of StepFail
38 stdout: Path to a file to put step stdout into. If used, stdout won't
39 appear in annotator's stdout (and |allow_subannotations| is
40 ignored).
iannucci 2016/09/12 19:41:07 I think this (and stdin+stderr) actually must be P
41 stderr: Path to a file to put step stderr into. If used, stderr won't
42 appear in annotator's stderr.
43 stdin: Path to a file to read step stdin from.
44 ok_ret: Allowed return code list.
iannucci 2016/09/12 19:41:07 set of return codes allowed. If the step process r
45 step_test_data: Possible associated step test data.
iannucci 2016/09/12 19:41:07 step_test_data (func -> recipe_test_api.StepTestDa
46 nest_level: the step's nesting level.
iannucci 2016/09/12 19:41:07 int?
47 """
48
49
50 def _make_step_config(**step):
51 """Galvanize a step dictionary into a formal StepConfig."""
52 step_config = StepConfig(
53 name=step.pop('name'),
54 cmd=step.pop('cmd', None),
55 cwd=step.pop('cwd', None),
56 env=step.pop('env', None),
57 allow_subannotations=step.pop('allow_subannotations', False),
58 trigger_specs=step.pop('trigger_specs', ()),
59 timeout=step.pop('timeout', None),
60 infra_step=step.pop('infra_step', False),
61 stdout=step.pop('stdout', None),
62 stderr=step.pop('stderr', None),
63 stdin=step.pop('stdin', None),
64 ok_ret=step.pop('ok_ret', {0}),
65 step_test_data=step.pop('step_test_data', None),
66 nest_level=step.pop('step_nest_level', 0),
67 )
68 if step:
69 unknown_keys = sorted(step.iterkeys())
70 raise KeyError('Unknown step dictionary keys: %s' % (
71 ', '.join(unknown_keys)))
72 return step_config
73
74
21 class StepFailure(Exception): 75 class StepFailure(Exception):
22 """ 76 """
23 This is the base class for all step failures. 77 This is the base class for all step failures.
24 78
25 Raising a StepFailure counts as 'running a step' for the purpose of 79 Raising a StepFailure counts as 'running a step' for the purpose of
26 infer_composite_step's logic. 80 infer_composite_step's logic.
27 """ 81 """
28 def __init__(self, name_or_reason, result=None): 82 def __init__(self, name_or_reason, result=None):
29 _STEP_CONTEXT['ran_step'][0] = True 83 _STEP_CONTEXT['ran_step'][0] = True
30 if result: 84 if result:
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 """ 718 """
665 Gets the BoundProperty version of this Property. Requires a name. 719 Gets the BoundProperty version of this Property. Requires a name.
666 """ 720 """
667 return BoundProperty( 721 return BoundProperty(
668 self._default, self.help, self.kind, name, property_type, module, 722 self._default, self.help, self.kind, name, property_type, module,
669 self.param_name) 723 self.param_name)
670 724
671 class UndefinedPropertyException(TypeError): 725 class UndefinedPropertyException(TypeError):
672 pass 726 pass
673 727
OLDNEW
« no previous file with comments | « no previous file | recipe_engine/run.py » ('j') | recipe_engine/step_runner.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698