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