diff options
Diffstat (limited to 'numpy/distutils/command/build_src.py')
-rw-r--r-- | numpy/distutils/command/build_src.py | 41 |
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 = [] |