6
from numpy.distutils.exec_command import exec_command
7
from base import Component
8
from utils import FileSource
10
def write_files(container):
11
s = ['creating files and directories:']
12
for filename, i in container.label_map.items():
13
content = container.list[i]
14
d,f = os.path.split(filename)
15
if d and not os.path.isdir(d):
16
s.append(' %s/' % (d))
17
if not Component._generate_dry_run:
19
s.append(' %s' % (filename))
20
if not Component._generate_dry_run:
22
if os.path.isfile(filename):
24
f = file(filename, 'r')
27
if 'is generated using ExtGen tool' in line:
33
s[-1] += ' - unknown file exists, skipping'
35
s[-1] += ' - extgen generated file exists, overwriting'
37
f = file(filename,'w')
43
class SetupPy(Component):
46
>>> from __init__ import *
47
>>> s = SetupPy('SetupPy_doctest')
48
>>> s += PyCModule('foo')
49
>>> s,o = s.execute('build_ext', '--inplace')
51
>>> import SetupPy_doctest as mypackage
52
>>> print mypackage.foo.__doc__ #doctest: +ELLIPSIS
53
This module 'foo' is generated with ExtGen from NumPy version...
56
template_setup_py_start = '''\
57
def configuration(parent_package='', top_path = ''):
58
from numpy.distutils.misc_util import Configuration
59
config = Configuration('',parent_package,top_path)'''
60
template_setup_py_end = '''\
62
if __name__ == "__main__":
63
from numpy.distutils.core import setup
64
setup(configuration=configuration)
66
template = '%(SourceWriter)s'
68
container_options = dict(
69
SourceWriter = dict(user_defined_str = write_files),
73
component_container_map = dict(
74
FileSource = 'SourceWriter',
75
ExtensionModule = 'TMP',
78
def initialize(self, build_dir, *components, **options):
79
self.name = self.path = build_dir
81
self.setup_py = setup_py = Component.PySource('extgen_setup.py')
82
self.init_py = init_py = Component.PySource('extgen__init__.py')
84
self.setup_py = setup_py = Component.PySource('setup.py')
85
self.init_py = init_py = Component.PySource('__init__.py')
87
setup_py += self.template_setup_py_start
92
map(self.add, components)
97
self.setup_py += self.template_setup_py_end
99
def execute(self, *args):
101
Run generated setup.py file with given arguments.
104
raise ValueError('need setup.py arguments')
105
self.info(self.generate(dry_run=False))
106
cmd = [sys.executable,'setup.py'] + list(args)
107
self.info('entering %r directory' % (self.path))
108
self.info('executing command %r' % (' '.join(cmd)))
110
r = exec_command(cmd, execute_in=self.path, use_tee=False)
112
self.info('leaving %r directory' % (self.path))
115
self.info('leaving %r directory' % (self.path))
123
if __name__ == "__main__":