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

Unified Diff: recipe_engine/util.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: Address comments. 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/util.py
diff --git a/recipe_engine/util.py b/recipe_engine/util.py
index 1bc3f4e54cfd6935288c60c188ce1e99d58e7575..fa92dc5210de9a30d1f117949b2c8302e79981c8 100644
--- a/recipe_engine/util.py
+++ b/recipe_engine/util.py
@@ -35,8 +35,11 @@ class ModuleInjectionSite(object):
class Placeholder(object):
"""Base class for command line argument placeholders. Do not use directly."""
- def __init__(self):
- self.name_pieces = None
+ def __init__(self, name=None):
+ if name is not None:
+ assert isinstance(name, basestring)
+ self.name = name
+ self.namespaces = None
@property
def backing_file(self): # pragma: no cover
@@ -62,9 +65,28 @@ class Placeholder(object):
pass
@property
- def name(self):
- assert self.name_pieces
- return "%s.%s" % self.name_pieces
+ def label(self):
+ if self.name is None:
+ return "%s.%s" % self.namespaces
iannucci 2016/03/22 22:54:24 %s.%s[DEFAULT] maybe?
stgao 2016/03/22 23:40:25 Maybe not, this will change the current behavior i
+ else:
+ return "%s.%s[%s]" % (self.namespaces[0], self.namespaces[1], self.name)
+
+
+class InputPlaceholder(Placeholder):
+ """Base class for json/raw_io input placeholders. Do not use directly."""
+ def result(self, presentation, test):
+ """Returned value will be discarded."""
+ pass
+ result.__doc__ = Placeholder.result.__doc__
+
+
+class OutputPlaceholder(Placeholder):
+ """Base class for json/raw_io output placeholders. Do not use directly."""
+
+ def result(self, presentation, test):
+ """Returned value will be added to the step result."""
+ pass
+ result.__doc__ = Placeholder.result.__doc__
class InputPlaceholder(Placeholder):
@@ -113,7 +135,7 @@ def returns_placeholder(func):
def inner(self, *args, **kwargs):
ret = static_call(self, func, *args, **kwargs)
assert isinstance(ret, Placeholder)
- ret.name_pieces = (self.name, static_name(self, func))
+ ret.namespaces = (self.name, static_name(self, func))
return ret
# prevent this placeholder-returning function from becoming a composite_step.
inner._non_step = True # pylint: disable=protected-access

Powered by Google App Engine
This is Rietveld 408576698