Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add symlinking for setup.py-defined scripts and entry_points['console_scripts'] #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions make_deb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import setuptools
from distutils.core import run_setup
import datetime
import os
from pkg_resources import resource_string
Expand Down Expand Up @@ -56,17 +58,24 @@ def _context_from_setuppy(self):
setuppy_path = os.path.join(self.rootdir, "setup.py")
if not os.path.exists(setuppy_path):
raise DebianConfigurationException("Failed to find setup.py")
stdout = subprocess.Popen(
["python", os.path.join(self.rootdir, "setup.py"),
"--name", "--version", "--maintainer", "--maintainer-email",
"--description"], stdout=subprocess.PIPE).communicate()

setup_values = stdout[0].decode('utf-8').split('\n')[:-1]
setup_names = ["name", "version", "maintainer", "maintainer_email",
"description"]
dist = run_setup(setuppy_path)
context = {
'name': dist.get_name(),
'version': dist.get_version(),
'maintainer': dist.get_maintainer(),
'maintainer_email': dist.get_maintainer_email(),
'description': dist.get_description(),
}

context = {}
for name, value in zip(setup_names, setup_values):
scripts = []
if dist.entry_points is not None and 'console_scripts' in dist.entry_points:
scripts += [script.split('=')[0] for script in dist.entry_points['console_scripts']]

if dist.scripts is not None:
scripts += [script.rsplit('/', 1)[-1] for script in dist.scripts]

for name, value in context.items():
while not value or value == UNKNOWN:
value = input(
"The '{}' parameter is not defined in setup.py. "
Expand All @@ -76,6 +85,8 @@ def _context_from_setuppy(self):

context[name] = value

context['scripts'] = scripts

return context

def render(self):
Expand All @@ -100,11 +111,12 @@ def render(self):
f.write(content)

# Need to to trigger separately because filename must change
trigger_content = Template(
resource_string("make_deb", "resources/debian/triggers.j2").
decode('utf-8')
).render(self.context)

trigger_filename = "%s.triggers" % self.context['name']
with open(os.path.join(output_dir, trigger_filename), "w") as f:
f.write(trigger_content+"\n")
for template in ['resources/debian/triggers.j2', 'resources/debian/links.j2']:
trigger_content = Template(
resource_string("make_deb", template).
decode('utf-8')
).render(self.context)

trigger_filename = "%s.%s" % (self.context['name'], template.split('.j2')[0].rsplit('/',1)[-1])
with open(os.path.join(output_dir, trigger_filename), "w") as f:
f.write(trigger_content+"\n")
3 changes: 3 additions & 0 deletions make_deb/resources/debian/links.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% for script_name in scripts %}
/usr/share/python/{{name}}/bin/{{script_name}} /usr/local/bin/{{script_name}}
{% endfor %}