Bug 1264831 - Try to detect decorators declared in the sandbox and add some automatic @wraps. r?gps
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -492,16 +492,24 @@ class ConfigureSandbox(dict):
# available there.
@wraps(template)
def wrapper(*args, **kwargs):
args = [maybe_prepare_function(arg) for arg in args]
kwargs = {k: maybe_prepare_function(v)
for k, v in kwargs.iteritems()}
ret = template(*args, **kwargs)
if isfunction(ret):
+ # We can't expect the sandboxed code to think about all the
+ # details of implementing decorators, so do some of the
+ # work for them. If the function takes exactly one function
+ # as argument and returns a function, it must be a
+ # decorator, so mark the returned function as wrapping the
+ # function passed in.
+ if len(args) == 1 and not kwargs and isfunction(args[0]):
+ ret = wraps(args[0])(ret)
return wrap_template(ret)
return ret
return wrapper
wrapper = wrap_template(template)
self._templates.add(wrapper)
return wrapper