Commit 634b0aef authored by Jason R. Coombs's avatar Jason R. Coombs

Rather than re-use globals of setuptools.launch, build a unique namespace in...

Rather than re-use globals of setuptools.launch, build a unique namespace in which to launch the script. Prevents imports from occuring relative to 'setuptools' on Python 2. Ref #490.
parent bdd0e2d6
......@@ -10,19 +10,26 @@ import tokenize
import sys
def load():
def run():
"""
Load the script in sys.argv[1] and run it as if it had
Run the script in sys.argv[1] as if it had
been invoked naturally.
"""
globals()['__file__'] = sys.argv[1]
__builtins__
script_name = sys.argv[1]
namespace = dict(
__file__ = script_name,
__name__ = '__main__',
__doc__ = None,
)
sys.argv[:] = sys.argv[1:]
open_ = getattr(tokenize, 'open', open)
script = open_(__file__).read()
script = open_(script_name).read()
norm_script = script.replace('\\r\\n', '\\n')
return compile(norm_script, __file__, 'exec')
code = compile(norm_script, script_name, 'exec')
exec(code, namespace)
if __name__ == '__main__':
exec(load())
run()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment