jpayne@68: """ jpayne@68: Launch the Python script on the command line after jpayne@68: setuptools is bootstrapped via import. jpayne@68: """ jpayne@68: jpayne@68: # Note that setuptools gets imported implicitly by the jpayne@68: # invocation of this script using python -m setuptools.launch jpayne@68: jpayne@68: import sys jpayne@68: import tokenize jpayne@68: jpayne@68: jpayne@68: def run(): jpayne@68: """ jpayne@68: Run the script in sys.argv[1] as if it had jpayne@68: been invoked naturally. jpayne@68: """ jpayne@68: __builtins__ jpayne@68: script_name = sys.argv[1] jpayne@68: namespace = dict( jpayne@68: __file__=script_name, jpayne@68: __name__='__main__', jpayne@68: __doc__=None, jpayne@68: ) jpayne@68: sys.argv[:] = sys.argv[1:] jpayne@68: jpayne@68: open_ = getattr(tokenize, 'open', open) jpayne@68: with open_(script_name) as fid: jpayne@68: script = fid.read() jpayne@68: norm_script = script.replace('\\r\\n', '\\n') jpayne@68: code = compile(norm_script, script_name, 'exec') jpayne@68: exec(code, namespace) jpayne@68: jpayne@68: jpayne@68: if __name__ == '__main__': jpayne@68: run()