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 DistutilsError,"%d errors while compiling %r with Pyrex" \ % (pyrex_result.num_errors, source) elif os.path.isfile(target_file): log.warn("Pyrex required for compiling %r but not available,"\ " using old target %r"\ % (source, target_file)) else: raise DistutilsError, "Pyrex required for compiling %r but not available" % ( source) new_sources.append(target_file) else: new_sources.append(source) return new_sources
def run_compile_test(item, link=0): """Run a single compile-only or compile-and-link test. If linking, the linked extension module is kept for use by later tests. """ try: mark_item(item, "failed") dir = path.dirname(item) name = path.basename(item) global mangled_module_name module_name, _ = os.path.splitext(name) mangled_module_name = "%d%s_" % (len(module_name), module_name) produces_include_files = name.startswith("i_") or name.startswith( "ia_") produces_api_file = name.startswith("a_") or name.startswith("ia_") is_error_test = (name[:2] == "e_" or name[:3] == "se_") options = Main.CompilationOptions(Main.default_options) if is_error_test: options.use_listing_file = 1 options.errors_to_stderr = 0 try: result = Main.compile(item, options) except CCompilerError: fail("C compilation error.") except: fail_with_exception("Exception raised in Pyrex compiler.") #print "result =", result.__dict__ ### if is_error_test: if result.num_errors == 0: fail("No errors produced, expected some") if result.listing_file is None: fail("No listing file produced") compare_with_reference(result.listing_file, show_diffs=0, line_munger=munge_error_line) remove_file(replace_suffix(item, ".c")) remove_file(replace_suffix(item, ".cpp")) else: if result.num_errors <> 0: #display_files(replace_suffix(item, ".lis")) fail("%s errors reported, expected none" % result.num_errors) if result.c_file is None: fail("No C file produced") compare_with_reference(result.c_file, show_diffs=1, line_munger=munge_c_line) if produces_include_files: if result.h_file is None: fail("No header file produced") compare_with_reference(result.h_file, show_diffs=1, line_munger=munge_c_line) if result.i_file is None: pass # .pxi files no longer produced by default #fail("No include file produced") else: compare_with_reference(result.i_file, show_diffs=1, line_munger=None) if produces_api_file: if result.api_file is None: fail("No api header file produced") compare_with_reference(result.api_file, show_diffs=1, line_munger=munge_c_line) try: result.object_file = c_compile(result.c_file) except CCompilerError: fail("C compilation error.") except: fail_with_exception("C compiler failed.") try: cplus_object_file = c_compile(result.c_file, cplus=1, obj_suffix=".cplus.o") except CCompilerError: fail("C++ compilation error.") except: fail_with_exception("C++ compiler failed.") if link: try: c_link(result.object_file) except CCompilerError: fail("C linking error.") remove_file(result.listing_file) remove_file(result.object_file) remove_file(cplus_object_file) mark_item(item, "passed") return "passed" except FailureError: return "failed"