def get_script_args(dist, executable=sys_executable, wininst=False): """Yield write_script() argument tuples for a distribution's entrypoints""" spec = str(dist.as_requirement()) header = get_script_header("", executable, wininst) for group in 'console_scripts', 'gui_scripts': for name, ep in dist.get_entry_map(group).items(): script_text = ( "# EASY-INSTALL-ENTRY-SCRIPT: %(spec)r,%(group)r,%(name)r\n" "__requires__ = %(spec)r\n" "import sys\n" "from pkg_resources import load_entry_point\n" "\n" "if __name__ == '__main__':" "\n" " sys.exit(\n" " load_entry_point(%(spec)r, %(group)r, %(name)r)()\n" " )\n" ) % locals() if sys.platform=='win32' or wininst: # On Windows/wininst, add a .py extension and an .exe launcher if group=='gui_scripts': ext, launcher = '-script.pyw', 'gui.exe' old = ['.pyw'] new_header = re.sub('(?i)python.exe','pythonw.exe',header) else: ext, launcher = '-script.py', 'cli.exe' old = ['.py','.pyc','.pyo'] new_header = re.sub('(?i)pythonw.exe','python.exe',header) if (sys.platform=='win32' and is_64bit()) or ('--plat-name=win-amd64' in sys.argv): launcher = launcher.replace(".", "-64.") else: # on linux (build system) always fall back to this launcher = launcher.replace(".", "-32.") if os.path.exists(new_header[2:-1]) or sys.platform!='win32': hdr = new_header else: hdr = header yield (name+ext, hdr+script_text, 't', [name+x for x in old]) yield ( name+'.exe', resource_string('setuptools', launcher), 'b' # write in binary mode ) else: # On other platforms, we assume the right thing to do is to # just write the stub with no extension. yield (name, header+script_text)
def get_script_args(dist, executable=sys_executable, wininst=False): """Yield write_script() argument tuples for a distribution's entrypoints""" header = get_script_header("", executable, wininst) for group in 'console_scripts', 'gui_scripts': for name, ep in dist.get_entry_map(group).items(): script_text = """import sys if __name__ == '__main__': import {module_name} sys.exit({module_name}.{attrs}()) """.format( module_name=ep.module_name, attrs='.'.join(ep.attrs), ) if sys.platform == 'win32' or wininst: # On Windows/wininst, add a .py extension and an .exe launcher if group == 'gui_scripts': ext, launcher = '-script.pyw', 'gui.exe' old = ['.pyw'] new_header = re.sub('(?i)python.exe', 'pythonw.exe', header) else: ext, launcher = '-script.py', 'cli.exe' old = ['.py', '.pyc', '.pyo'] new_header = re.sub('(?i)pythonw.exe', 'python.exe', header) if is_64bit(): launcher = launcher.replace(".", "-64.") else: launcher = launcher.replace(".", "-32.") if os.path.exists(new_header[2:-1]) or sys.platform != 'win32': hdr = new_header else: hdr = header yield (name + ext, hdr + script_text, 't', [name + x for x in old]) yield ( name + '.exe', resource_string('setuptools', launcher), 'b' # write in binary mode ) else: # On other platforms, we assume the right thing to do is to # just write the stub with no extension. yield (name, header + script_text)
def get_script_args(dist, executable=sys_executable, wininst=False): """Yield write_script() argument tuples for a distribution's entrypoints""" header = get_script_header("", executable, wininst) for group in 'console_scripts', 'gui_scripts': for name, ep in dist.get_entry_map(group).items(): script_text = """import sys if __name__ == '__main__': import {module_name} sys.exit({module_name}.{attrs}()) """.format(module_name=ep.module_name, attrs='.'.join(ep.attrs), ) if sys.platform == 'win32' or wininst: # On Windows/wininst, add a .py extension and an .exe launcher if group == 'gui_scripts': ext, launcher = '-script.pyw', 'gui.exe' old = ['.pyw'] new_header = re.sub('(?i)python.exe', 'pythonw.exe', header) else: ext, launcher = '-script.py', 'cli.exe' old = ['.py', '.pyc', '.pyo'] new_header = re.sub('(?i)pythonw.exe', 'python.exe', header) if is_64bit(): launcher = launcher.replace(".", "-64.") else: launcher = launcher.replace(".", "-32.") if os.path.exists(new_header[2:-1]) or sys.platform != 'win32': hdr = new_header else: hdr = header yield (name+ext, hdr+script_text, 't', [name+x for x in old]) yield ( name+'.exe', resource_string('setuptools', launcher), 'b' # write in binary mode ) else: # On other platforms, we assume the right thing to do is to # just write the stub with no extension. yield (name, header+script_text)