# HG changeset patch # User Jeff Hammel # Date 1295056508 28800 # Node ID 697568ba4a2254d94f5dcab4880c952bd99780f5 # Parent 32893f67f85db2a384efcb0a38c293d1dd334f9c make the python package template a little fancier diff -r 32893f67f85d -r 697568ba4a22 makeitso/python.py --- a/makeitso/python.py Fri Jan 14 07:35:19 2011 -0800 +++ b/makeitso/python.py Fri Jan 14 17:55:08 2011 -0800 @@ -16,8 +16,10 @@ * ./web.py : a webob web handler """ +import os import sys from cli import MakeItSoCLI +from makeitso import ContentTemplate from optparse import OptionParser from template import MakeItSoTemplate from template import Variable @@ -37,23 +39,46 @@ # things that go in setup.py dependencies = {'web.py': ['webob'], 'template.py': ['MakeItSo']} - console_scripts = {'main.py': '{{project}}.main:main', - 'template.py': '{{project}}.template:main' + console_scripts = {'main.py': '{{project}} = {{project}}.main:main', + 'template.py': '{{project}}-template = {{project}}.template:main' } def __init__(self, **kw): MakeItSoTemplate.__init__(self, **kw) + # TODO: get the templates you actually care about [maybe from the CLI?] + def pre(self, variables, output): """ sanitize some variables """ + # get project from output directory + variables['project'] = os.path.basename(output) + # dependencies - dependencies = [] - + dependencies = set([]) + for template, dependency in self.dependencies: + dependencies.update(dependency) + dependencies = list(dependencies) + variables['dependencies'] = dependencies + # console_scripts console_scripts = [] + for template, console_script in self.console_scripts: + console_scripts.add(console_script) + if console_scripts: + s = 'setup(' # placeholder string + script_strings = ['[console_scripts]'] + for console_script in console_scripts: + template = ContentTemplate(console_script) + output = template.substitute(project=variables['project']) + script_strings.append(output) + variables['console_scripts'] = '\n'.join([' ' * len(s) + i + for i in script_strings]) + else: + variables['console_scripts'] = '' + class PythonPackageCLI(MakeItSoCLI): """ diff -r 32893f67f85d -r 697568ba4a22 makeitso/python_package/setup.py --- a/makeitso/python_package/setup.py Fri Jan 14 07:35:19 2011 -0800 +++ b/makeitso/python_package/setup.py Fri Jan 14 17:55:08 2011 -0800 @@ -9,6 +9,8 @@ version = "0.0" +depdendencies = {{dependencies}} + setup(name='{{project}}', version=version, description="{{description}}", @@ -21,11 +23,11 @@ packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True, zip_safe=False, - install_requires=[ - # -*- Extra requirements: -*- - ], + install_requires=dependencies, entry_points=""" # -*- Entry points: -*- + + {{console_scripts}} """, )