Mercurial > hg > MakeItSo
diff makeitso/python.py @ 109:697568ba4a22
make the python package template a little fancier
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 14 Jan 2011 17:55:08 -0800 |
parents | 32893f67f85d |
children | bad70fb08b15 |
line wrap: on
line diff
--- 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): """