Bug 1256573 - Remove the @advanced primitive. r?nalexander
--- a/python/mozbuild/mozbuild/configure/__init__.py
+++ b/python/mozbuild/mozbuild/configure/__init__.py
@@ -53,29 +53,28 @@ def forbidden_import(*args, **kwargs):
raise ImportError('Importing modules is forbidden')
class ConfigureSandbox(dict):
"""Represents a sandbox for executing Python code for build configuration.
This is a different kind of sandboxing than the one used for moz.build
processing.
- The sandbox has 9 primitives:
+ The sandbox has 8 primitives:
- option
- depends
- template
- imports
- - advanced
- include
- set_config
- set_define
- imply_option
`option`, `include`, `set_config`, `set_define` and `imply_option` are
- functions. `depends`, `template`, `imports` and `advanced` are decorators.
+ functions. `depends`, `template`, and `imports` are decorators.
These primitives are declared as name_impl methods to this class and
the mapping name -> name_impl is done automatically in __getitem__.
Additional primitives should be frowned upon to keep the sandbox itself as
simple as possible. Instead, helpers should be created within the sandbox
with the existing primitives.
@@ -385,18 +384,18 @@ class ConfigureSandbox(dict):
if not isinstance(what, types.StringTypes):
raise TypeError("Unexpected type: '%s'" % type(what))
self.exec_file(what)
def template_impl(self, func):
'''Implementation of @template.
This function is a decorator. Template functions are called
immediately. They are altered so that their global namespace exposes
- a limited set of functions from os.path, as well as `advanced`,
- `depends` and `option`.
+ a limited set of functions from os.path, as well as `depends` and
+ `option`.
Templates allow to simplify repetitive constructs, or to implement
helper decorators and somesuch.
'''
template, glob = self._prepare_function(func)
glob.update(
(k[:-len('_impl')], getattr(self, k))
for k in dir(self) if k.endswith('_impl') and k != 'template_impl'
)
@@ -422,23 +421,16 @@ class ConfigureSandbox(dict):
return wrap_template(ret)
return ret
return wrapper
wrapper = wrap_template(template)
self._templates.add(wrapper)
return wrapper
- def advanced_impl(self, func):
- '''Implementation of @advanced.
- This function gives the decorated function access to the complete set
- of builtins, allowing the import keyword as an expected side effect.
- '''
- return self.imports_impl(_import='__builtin__', _as='__builtins__')(func)
-
RE_MODULE = re.compile('^[a-zA-Z0-9_\.]+$')
def imports_impl(self, _import, _from=None, _as=None):
'''Implementation of @imports.
This decorator imports the given _import from the given _from module
optionally under a different _as name.
The options correspond to the various forms for the import builtin.
@imports('sys')
@@ -603,17 +595,17 @@ class ConfigureSandbox(dict):
raise TypeError("Unexpected type: '%s'" % type(value))
option = value.format(option)
self._helper.add(option, 'implied')
self._implied_options[option] = inspect.stack()[1], reason
def _prepare_function(self, func):
'''Alter the given function global namespace with the common ground
- for @depends, @template and @advanced.
+ for @depends, and @template.
'''
if not inspect.isfunction(func):
raise TypeError("Unexpected type: '%s'" % type(func))
if func in self._prepared_functions:
return func, func.func_globals
glob = SandboxedGlobal(func.func_globals)
glob.update(