diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2014-07-05 14:42:49 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2014-07-05 14:42:49 -0400 |
commit | c4ecbd1e58a3384a5ab730450fa5487e48b68721 (patch) | |
tree | 48c2ea3b73cd70fdb47d2c1e4d2ee966c36b5377 /setuptools/sandbox.py | |
parent | f3829d8bd0cd852be133f8822aa4493a7a12fd51 (diff) | |
download | external_python_setuptools-c4ecbd1e58a3384a5ab730450fa5487e48b68721.tar.gz external_python_setuptools-c4ecbd1e58a3384a5ab730450fa5487e48b68721.tar.bz2 external_python_setuptools-c4ecbd1e58a3384a5ab730450fa5487e48b68721.zip |
Since Python 3 will always need the _execfile functionality (to fulfill the test in test_sandbox), this functionality should become part of the core implementation.
Diffstat (limited to 'setuptools/sandbox.py')
-rwxr-xr-x | setuptools/sandbox.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/setuptools/sandbox.py b/setuptools/sandbox.py index dc6e54bf..7985e9ee 100755 --- a/setuptools/sandbox.py +++ b/setuptools/sandbox.py @@ -20,12 +20,23 @@ _open = open from distutils.errors import DistutilsError from pkg_resources import working_set -from setuptools.compat import builtins, execfile +from setuptools.compat import builtins __all__ = [ "AbstractSandbox", "DirectorySandbox", "SandboxViolation", "run_setup", ] +def _execfile(filename, globals, locals=None): + """ + Python 3 implementation of execfile. + """ + with open(filename, 'rb') as stream: + script = stream.read() + if locals is None: + locals = globals + code = compile(script, filename, 'exec') + exec(code, globals, locals) + def run_setup(setup_script, args): """Run a distutils setup script, sandboxed in its directory""" old_dir = os.getcwd() @@ -46,12 +57,10 @@ def run_setup(setup_script, args): # reset to include setup dir, w/clean callback list working_set.__init__() working_set.callbacks.append(lambda dist:dist.activate()) - DirectorySandbox(setup_dir).run( - lambda: execfile( - "setup.py", - {'__file__':setup_script, '__name__':'__main__'} - ) - ) + def runner(): + ns = dict(__file__=setup_script, __name__='__main__') + _execfile(setup_script, ns) + DirectorySandbox(setup_dir).run(runner) except SystemExit: v = sys.exc_info()[1] if v.args and v.args[0]: |