summaryrefslogtreecommitdiff
path: root/numpy/distutils/command/build_src.py
diff options
context:
space:
mode:
authorPearu Peterson <pearu.peterson@gmail.com>2006-02-06 10:29:49 +0000
committerPearu Peterson <pearu.peterson@gmail.com>2006-02-06 10:29:49 +0000
commitd8342ac3f90e7e0f3136293762db055de2c37682 (patch)
treeb3f03c167ac83350afcb3a16f12e954cc4bf05bb /numpy/distutils/command/build_src.py
parentad1f3dbd434e03db560406afe8363599aac42c79 (diff)
downloadnumpy-d8342ac3f90e7e0f3136293762db055de2c37682.tar.gz
Added pyrex support to numpy.distutils.
Diffstat (limited to 'numpy/distutils/command/build_src.py')
-rw-r--r--numpy/distutils/command/build_src.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/numpy/distutils/command/build_src.py b/numpy/distutils/command/build_src.py
index d3f926ffa..cc22115c7 100644
--- a/numpy/distutils/command/build_src.py
+++ b/numpy/distutils/command/build_src.py
@@ -214,6 +214,8 @@ class build_src(build_ext.build_ext):
sources = self.f2py_sources(sources, ext)
+ sources = self.pyrex_sources(sources, ext)
+
sources, py_files = self.filter_py_files(sources)
if not self.py_modules_dict.has_key(package):
@@ -328,6 +330,45 @@ class build_src(build_ext.build_ext):
new_sources.append(source)
return new_sources
+ def pyrex_sources(self, sources, extension):
+ have_pyrex = False
+ try:
+ import Pyrex
+ have_pyrex = True
+ except ImportError:
+ pass
+ new_sources = []
+ ext_name = extension.name.split('.')[-1]
+ for source in sources:
+ (base, ext) = os.path.splitext(source)
+ if ext == '.pyx':
+ if self.inplace or not have_pyrex:
+ target_dir = os.path.dirname(base)
+ else:
+ target_dir = appendpath(self.build_src, os.path.dirname(base))
+ target_file = os.path.join(target_dir, ext_name + '.c')
+ depends = [source] + extension.depends
+ if (self.force or newer_group(depends, target_file, 'newer')):
+ if have_pyrex:
+ log.info("pyrexc:> %s" % (target_file))
+ self.mkpath(target_dir)
+ from Pyrex.Compiler import Main
+ options = Main.CompilationOptions(
+ defaults=Main.default_options,
+ output_file=target_file)
+ pyrex_result = Main.compile(source, options=options)
+ if pyrex_result.num_errors != 0:
+ raise RuntimeError("%d errors in Pyrex compile" %
+ pyrex_result.num_errors)
+ else:
+ log.info("Pyrex needed to compile %s but not available."\
+ " Using old target %s"\
+ % (source, target_file))
+ new_sources.append(target_file)
+ else:
+ new_sources.append(source)
+ return new_sources
+
def f2py_sources(self, sources, extension):
new_sources = []
f2py_sources = []