comparison makeitso/python.py @ 159:cfd4f1e91090

wip
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 30 Jul 2013 15:20:38 -0700
parents 386a44a52139
children 9033a5f11b92
comparison
equal deleted inserted replaced
158:ff1f41a18da9 159:cfd4f1e91090
25 from template import Variable 25 from template import Variable
26 26
27 class PythonTemplate(MakeItSoTemplate): 27 class PythonTemplate(MakeItSoTemplate):
28 """abstract base class for python-type templates""" 28 """abstract base class for python-type templates"""
29 29
30 def path2name(self, path):
31 return os.path.basename(path.rstrip(os.path.sep))
30 32
31 class PythonScriptTemplate(PythonTemplate): 33 class PythonScriptTemplate(PythonTemplate):
32 """template for a single python script""" 34 """template for a single python script"""
33 templates = [os.path.join('python_package', '{{package}}', 'main.py')] 35 templates = [('python_package', '{{package}}', '{{main}}.py')]
34 36
35 37
36 class PythonModuleTemplate(PythonTemplate): 38 class PythonModuleTemplate(PythonTemplate):
37 """single module python package""" 39 """single module python package"""
38 # TODO: this should use the same files as PythonPackageTemplate 40 # TODO: this should use the same files as PythonPackageTemplate
39 templates = ['python_module'] 41 templates = ['python_module',
42 ('python_package', '{{package}}', '{{main}}.py')]
43 vars = [Variable('description')]
44 look = False
40 45
46 def pre(self, variables, output):
47 variables['module'] = variables['main'] = path2name(output)
41 48
42 class PythonPackageTemplate(PythonTemplate): 49 class PythonPackageTemplate(PythonTemplate):
43 """ 50 """
44 python package template 51 python package template
45 """ 52 """
46 name = 'python-package' 53 name = 'python-package'
47 templates = ['python_package'] 54 templates = ['python_package']
48 vars = [Variable('description'), 55 vars = [Variable('description'),
49 Variable('author', 'author of the package'), 56 Variable('author', 'author of the package'),
50 Variable('email', "author's email"), 57 Variable('email', "author's email"),
51 Variable('url'), 58 Variable('url', 'project url'),
52 Variable('repo', 'project repository'), 59 Variable('repo', 'project repository'),
53 ] 60 ]
54 look = False 61 look = False
55 62
56 # things that go in setup.py 63 # things that go in setup.py
57 dependencies = {'web.py': ['webob'], 64 dependencies = {'web.py': ['webob'],
58 'template.py': ['MakeItSo']} 65 'template.py': ['MakeItSo']}
59 console_scripts = {'main.py': '{{project}} = {{project}}.main:main', 66 console_scripts = {'main.py': '{{project}} = {{project}}.{{main}}:main',
60 'template.py': '{{project}}-template = {{project}}.template:main' 67 'template.py': '{{project}}-template = {{project}}.template:main'
61 } 68 }
62 69
63 def __init__(self, **kw): 70 def __init__(self, **kw):
64 MakeItSoTemplate.__init__(self, **kw) 71 MakeItSoTemplate.__init__(self, **kw)
69 """ 76 """
70 sanitize some variables 77 sanitize some variables
71 """ 78 """
72 79
73 # get project from output directory 80 # get project from output directory
74 variables['project'] = os.path.basename(output) 81 variables['project'] = self.path2name(output)
75 82
76 # get package name from project 83 # get package name from project
77 # XXX could have looser restrictions with transforms 84 # XXX could have looser restrictions with transforms
78 assert variables['project'].isalnum(), 'Project name must be just letters, you gave %s' % variables['project'] 85 assert variables['project'].isalnum(), 'Project name must be just letters, you gave %s' % variables['project']
79 variables['package'] = variables['project'].lower() 86 variables['package'] = variables['project'].lower()
87
88 # name of CLI main file
89 variables.setdefault('main', 'main')
80 90
81 # dependencies 91 # dependencies
82 dependencies = set([]) 92 dependencies = set([])
83 for template, dependency in self.dependencies.items(): 93 for template, dependency in self.dependencies.items():
84 dependencies.update(dependency) 94 dependencies.update(dependency)