diff --git a/pbr/packaging.py b/pbr/packaging.py index f929b4c4..9f4221cc 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -308,22 +308,27 @@ def have_nose(): } +def generate_script(group, entry_point, name, header, template): + """Generate the script based on the template.""" + if not entry_point.attrs or len(entry_point.attrs) > 2: + raise ValueError("Script targets must be of the form " + "'func' or 'Class.class_method'.") + script_text = template % dict( + group=group, + module_name=entry_point.module_name, + import_target=entry_point.attrs[0], + invoke_target='.'.join(entry_point.attrs), + ) + return (name, header + script_text) + + def override_get_script_args( dist, executable=os.path.normpath(sys.executable), is_wininst=False): """Override entrypoints console_script.""" header = easy_install.get_script_header("", executable, is_wininst) for group, template in ENTRY_POINTS_MAP.items(): for name, ep in dist.get_entry_map(group).items(): - if not ep.attrs or len(ep.attrs) > 2: - raise ValueError("Script targets must be of the form " - "'func' or 'Class.class_method'.") - script_text = template % dict( - group=group, - module_name=ep.module_name, - import_target=ep.attrs[0], - invoke_target='.'.join(ep.attrs), - ) - yield (name, header + script_text) + yield generate_script(group, ep, name, header, template) class LocalDevelop(develop.develop): @@ -342,6 +347,14 @@ class LocalInstallScripts(install_scripts.install_scripts): """Intercepts console scripts entry_points.""" command_name = 'install_scripts' + def _make_wsgi_scripts_only(self, dist, executable, is_wininst): + header = easy_install.get_script_header("", executable, is_wininst) + wsgi_script_template = ENTRY_POINTS_MAP['wsgi_scripts'] + for name, ep in dist.get_entry_map('wsgi_scripts').items(): + script_name, content = generate_script( + 'wsgi_scripts', ep, name, header, wsgi_script_template) + self.write_script(script_name, content) + def run(self): import distutils.command.install_scripts @@ -351,9 +364,6 @@ def run(self): distutils.command.install_scripts.install_scripts.run(self) else: self.outfiles = [] - if self.no_ep: - # don't install entry point scripts into .egg file! - return ei_cmd = self.get_finalized_command("egg_info") dist = pkg_resources.Distribution( @@ -361,13 +371,24 @@ def run(self): pkg_resources.PathMetadata(ei_cmd.egg_base, ei_cmd.egg_info), ei_cmd.egg_name, ei_cmd.egg_version, ) - bs_cmd = self.get_finalized_command('build_scripts') + + bs_cmd = self.get_finalized_command("build_scripts") executable = getattr( bs_cmd, 'executable', easy_install.sys_executable) + is_wininst = getattr( self.get_finalized_command("bdist_wininst"), '_is_running', False ) + if 'bdist_wheel' in self.distribution.have_run: + # We're building a wheel which has no way of generating mod_wsgi + # scripts for us. Let's build them. + self._make_wsgi_scripts_only(dist, executable, is_wininst) + + if self.no_ep: + # don't install entry point scripts into .egg file! + return + if os.name != 'nt': get_script_args = override_get_script_args else: