Mercurial > hg > MakeItSo
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 108:32893f67f85d | 109:697568ba4a22 |
|---|---|
| 14 * ./template.py : a MakeItSo template for project creation | 14 * ./template.py : a MakeItSo template for project creation |
| 15 * ./tests : doctest suite for the package | 15 * ./tests : doctest suite for the package |
| 16 * ./web.py : a webob web handler | 16 * ./web.py : a webob web handler |
| 17 """ | 17 """ |
| 18 | 18 |
| 19 import os | |
| 19 import sys | 20 import sys |
| 20 from cli import MakeItSoCLI | 21 from cli import MakeItSoCLI |
| 22 from makeitso import ContentTemplate | |
| 21 from optparse import OptionParser | 23 from optparse import OptionParser |
| 22 from template import MakeItSoTemplate | 24 from template import MakeItSoTemplate |
| 23 from template import Variable | 25 from template import Variable |
| 24 | 26 |
| 25 class PythonPackageTemplate(MakeItSoTemplate): | 27 class PythonPackageTemplate(MakeItSoTemplate): |
| 35 look = True | 37 look = True |
| 36 | 38 |
| 37 # things that go in setup.py | 39 # things that go in setup.py |
| 38 dependencies = {'web.py': ['webob'], | 40 dependencies = {'web.py': ['webob'], |
| 39 'template.py': ['MakeItSo']} | 41 'template.py': ['MakeItSo']} |
| 40 console_scripts = {'main.py': '{{project}}.main:main', | 42 console_scripts = {'main.py': '{{project}} = {{project}}.main:main', |
| 41 'template.py': '{{project}}.template:main' | 43 'template.py': '{{project}}-template = {{project}}.template:main' |
| 42 } | 44 } |
| 43 | 45 |
| 44 def __init__(self, **kw): | 46 def __init__(self, **kw): |
| 45 MakeItSoTemplate.__init__(self, **kw) | 47 MakeItSoTemplate.__init__(self, **kw) |
| 48 | |
| 49 # TODO: get the templates you actually care about [maybe from the CLI?] | |
| 46 | 50 |
| 47 def pre(self, variables, output): | 51 def pre(self, variables, output): |
| 48 """ | 52 """ |
| 49 sanitize some variables | 53 sanitize some variables |
| 50 """ | 54 """ |
| 51 | 55 |
| 56 # get project from output directory | |
| 57 variables['project'] = os.path.basename(output) | |
| 58 | |
| 52 # dependencies | 59 # dependencies |
| 53 dependencies = [] | 60 dependencies = set([]) |
| 54 | 61 for template, dependency in self.dependencies: |
| 62 dependencies.update(dependency) | |
| 63 dependencies = list(dependencies) | |
| 64 variables['dependencies'] = dependencies | |
| 65 | |
| 55 # console_scripts | 66 # console_scripts |
| 56 console_scripts = [] | 67 console_scripts = [] |
| 68 for template, console_script in self.console_scripts: | |
| 69 console_scripts.add(console_script) | |
| 70 if console_scripts: | |
| 71 s = 'setup(' # placeholder string | |
| 72 script_strings = ['[console_scripts]'] | |
| 73 for console_script in console_scripts: | |
| 74 template = ContentTemplate(console_script) | |
| 75 output = template.substitute(project=variables['project']) | |
| 76 script_strings.append(output) | |
| 77 variables['console_scripts'] = '\n'.join([' ' * len(s) + i | |
| 78 for i in script_strings]) | |
| 79 else: | |
| 80 variables['console_scripts'] = '' | |
| 81 | |
| 57 | 82 |
| 58 class PythonPackageCLI(MakeItSoCLI): | 83 class PythonPackageCLI(MakeItSoCLI): |
| 59 """ | 84 """ |
| 60 CLI front end for the python package template | 85 CLI front end for the python package template |
| 61 """ | 86 """ |
