diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2021-11-10 12:12:49 -0500 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-11-10 12:13:40 -0500 |
| commit | 958ce2304e153b274e2ff7b40b1e7d5ddd214904 (patch) | |
| tree | bb1b77cfc08c31fb69eebdb0c66f5c0dde3f5223 /setuptools/launch.py | |
| parent | 23f63dd44c5d9f75de195833d25a5f2872220c2b (diff) | |
| parent | 8af23a41194ae747faf3e60f9cc19141b5e7ad24 (diff) | |
| download | python-setuptools-git-958ce2304e153b274e2ff7b40b1e7d5ddd214904.tar.gz | |
Merge pull request #2866 into main.
Diffstat (limited to 'setuptools/launch.py')
| -rw-r--r-- | setuptools/launch.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/setuptools/launch.py b/setuptools/launch.py new file mode 100644 index 00000000..0208fdf3 --- /dev/null +++ b/setuptools/launch.py @@ -0,0 +1,36 @@ +""" +Launch the Python script on the command line after +setuptools is bootstrapped via import. +""" + +# Note that setuptools gets imported implicitly by the +# invocation of this script using python -m setuptools.launch + +import tokenize +import sys + + +def run(): + """ + Run the script in sys.argv[1] as if it had + been invoked naturally. + """ + __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) + with open_(script_name) as fid: + script = fid.read() + norm_script = script.replace('\\r\\n', '\\n') + code = compile(norm_script, script_name, 'exec') + exec(code, namespace) + + +if __name__ == '__main__': + run() |
