Skip to content

Commit

Permalink
Include wsgi_scripts in generated wheels
Browse files Browse the repository at this point in the history
Closes-bug: #1542383
  • Loading branch information
sigmavirus24 committed Feb 12, 2016
1 parent d19459d commit 8e996fb
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions pbr/packaging.py
Expand Up @@ -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):
Expand All @@ -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

Expand All @@ -351,23 +364,31 @@ 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(
ei_cmd.egg_base,
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:
Expand Down

0 comments on commit 8e996fb

Please sign in to comment.