Index: recipe_modules/step/api.py |
diff --git a/recipe_modules/step/api.py b/recipe_modules/step/api.py |
index 8530f6ffdafcd8d71d8595732653e2a08a79fa7c..e26db2c4c8aabd382ea06ca0a30ad746ccebe16c 100644 |
--- a/recipe_modules/step/api.py |
+++ b/recipe_modules/step/api.py |
@@ -74,9 +74,23 @@ class StepApi(recipe_api.RecipeApiPlain): |
@property |
def context(self): |
- """ See recipe_api.py for docs. """ |
+ """Returns a context manager which can set values applying to all steps |
+ within the block. |
+ |
+ Example usage: |
+ with api.step.context({'cwd': api.path['checkout']}): |
+ api.step(...) |
+ """ |
return recipe_api.context |
+ def get_from_context(self, key, default=None): |
+ """Returns |key| from context if present, otherwise |default|.""" |
iannucci
2017/02/01 17:47:00
Returns |key|'s value from context...
Paweł Hajdan Jr.
2017/02/01 17:50:25
Done.
|
+ return recipe_api._STEP_CONTEXT.get(key, default) |
+ |
+ def combine_with_context(self, key, value): |
+ """Combines |value| with the value for |key| in current context, if any.""" |
iannucci
2017/02/01 17:47:00
... and returns the combined value.
It would be r
Paweł Hajdan Jr.
2017/02/01 17:50:25
Done.
|
+ return recipe_api._STEP_CONTEXT.get_with_context(key, value) |
+ |
@contextlib.contextmanager |
def nest(self, name): |
"""Nest is the high-level interface to annotated hierarchical steps. |
@@ -171,9 +185,6 @@ class StepApi(recipe_api.RecipeApiPlain): |
kwargs['timeout'] = timeout |
kwargs['ok_ret'] = ok_ret |
- # Obtain information from composite step parent. |
- compositor = recipe_api._STEP_CONTEXT |
- |
# Calculate our full step name. If a step already has that name, add an |
# index to the end of it. |
# |
@@ -181,7 +192,7 @@ class StepApi(recipe_api.RecipeApiPlain): |
# by the user. If this happens, we'll continue appending indexes until we |
# have a unique step name. |
while True: |
- full_name = compositor.get_with_context('name', name) |
+ full_name = self.combine_with_context('name', name) |
iannucci
2017/02/01 17:47:00
ew, I forgot about name. this is used to implement
Paweł Hajdan Jr.
2017/02/01 17:50:25
Yes, see api.step.nest .
|
if full_name not in self._seen_steps: |
break |
@@ -191,11 +202,11 @@ class StepApi(recipe_api.RecipeApiPlain): |
self._seen_steps.add(full_name) |
if 'cwd' not in kwargs: |
- kwargs['cwd'] = compositor.get('cwd') |
- kwargs['env'] = compositor.get_with_context('env', kwargs.get('env', {})) |
- kwargs['infra_step'] = compositor.get_with_context( |
+ kwargs['cwd'] = self.get_from_context('cwd') |
+ kwargs['env'] = self.combine_with_context('env', kwargs.get('env', {})) |
+ kwargs['infra_step'] = self.combine_with_context( |
'infra_step', bool(infra_step)) |
- kwargs['step_nest_level'] = compositor.get_with_context('nest_level', 0) |
+ kwargs['step_nest_level'] = self.combine_with_context('nest_level', 0) |
kwargs['name'] = full_name |
kwargs['base_name'] = name |