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

Unified Diff: recipe_engine/step_runner.py

Issue 1773273003: Make output placeholders like json.output index-able by name. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Rebase uppon https://codereview.chromium.org/1785543004/ Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: recipe_engine/step_runner.py
diff --git a/recipe_engine/step_runner.py b/recipe_engine/step_runner.py
index ae127e99692fabda3d9545dc8ff4cd0eaac94dc0..bfa10f6eee24e527a58554ed3046f6f1f36efe5f 100644
--- a/recipe_engine/step_runner.py
+++ b/recipe_engine/step_runner.py
@@ -449,19 +449,26 @@ def render_step(step, step_test):
# Process 'cmd', rendering placeholders there.
input_phs = collections.defaultdict(lambda: collections.defaultdict(list))
- output_phs = collections.defaultdict(lambda: collections.defaultdict(list))
+ output_phs = collections.defaultdict(
+ lambda: collections.defaultdict(collections.OrderedDict))
new_cmd = []
for item in step.get('cmd', []):
if isinstance(item, util.Placeholder):
- module_name, placeholder_name = item.name_pieces
+ module_name, placeholder_name = item.namespaces
if isinstance(item, util.InputPlaceholder):
- tdata = step_test.pop_input_placeholder(item.name_pieces)
+ tdata = step_test.pop_input_placeholder(module_name, placeholder_name)
input_phs[module_name][placeholder_name].append((item, tdata))
else:
assert isinstance(item, util.OutputPlaceholder), (
'Not an OutputPlaceholder: %r' % item)
- tdata = step_test.pop_output_placeholder(item.name_pieces)
- output_phs[module_name][placeholder_name].append((item, tdata))
+ # This assert also ensures at most one placeholder has the default name.
+ assert item.name not in output_phs[module_name][placeholder_name], (
+ 'Step "%s" has multiple output placeholders of %s.%s. Please '
+ 'specify explicit and different names for them.' % (
+ step['name'], module_name, placeholder_name))
+ tdata = step_test.pop_output_placeholder(
+ module_name, placeholder_name, item.name)
+ output_phs[module_name][placeholder_name][item.name] = (item, tdata)
new_cmd.extend(item.render(tdata))
else:
new_cmd.append(item)
@@ -512,10 +519,22 @@ def construct_step_result(step, retcode, placeholders):
o = BlankObject()
setattr(step_result, module_name, o)
- for placeholder_name, items in pholders.iteritems():
- lst = [ph.result(step_result.presentation, td) for ph, td in items]
- setattr(o, placeholder_name+"_all", lst)
- setattr(o, placeholder_name, lst[0])
+ for placeholder_name, instances in pholders.iteritems():
+ named_results = {}
+ for _, (ph, td) in instances.iteritems():
+ named_results[ph.name] = ph.result(step_result.presentation, td)
+ setattr(o, placeholder_name + "s", named_results)
+
+ default_result = None
+ if len(named_results) == 1: # Only 1 output placeholder.
+ default_result = named_results.values()[0]
+ else:
+ # 2+ output placeholder, check for the one without an explicit name.
+ for ph, _ in instances.values():
+ if ph.name is None:
+ default_result = named_results[ph.name]
+ break
+ setattr(o, placeholder_name, default_result)
# Placeholders that are used with IO redirection.
for key in ('stdout', 'stderr', 'stdin'):

Powered by Google App Engine
This is Rietveld 408576698