Example #1
0
 def compile(self, source, options=None):
     # Compile a Pyrex implementation file in this context
     # and return a CompilationResult.
     if not options:
         options = default_options
     result = CompilationResult()
     cwd = os.getcwd()
     source = os.path.join(cwd, source)
     if options.use_listing_file:
         result.listing_file = replace_suffix(source, ".lis")
         Errors.open_listing_file(result.listing_file,
                                  echo_to_stderr=options.errors_to_stderr)
     else:
         Errors.open_listing_file(None)
     if options.output_file:
         result.c_file = os.path.join(cwd, options.output_file)
     else:
         if options.cplus:
             result.c_file = replace_suffix(source, cplus_suffix)
         else:
             result.c_file = map_suffix(source, pyx_to_c_suffix, ".c")
     module_name = self.extract_module_name(source)
     initial_pos = (source, 1, 0)
     def_scope = self.find_module(module_name, pos=initial_pos, need_pxd=0)
     imp_scope = ImplementationScope(def_scope)
     errors_occurred = False
     try:
         tree = self.parse(source, imp_scope, pxd=0)
         tree.process_implementation(imp_scope, options, result)
     except CompileError:
         errors_occurred = True
     Errors.close_listing_file()
     result.num_errors = Errors.num_errors
     if result.num_errors > 0:
         errors_occurred = True
     if errors_occurred and result.c_file:
         try:
             st = os.stat(source)
             castrate_file(result.c_file, st)
         except EnvironmentError:
             pass
         result.c_file = None
     if result.c_file and not options.c_only and c_compile:
         result.object_file = c_compile(result.c_file,
                                        verbose_flag=options.show_version,
                                        cplus=options.cplus)
         if not options.obj_only and c_link:
             result.extension_file = c_link(
                 result.object_file,
                 extra_objects=options.objects,
                 verbose_flag=options.show_version,
                 cplus=options.cplus)
     return result
Example #2
0
 def __init__(self, source, options):
     cwd = os.getcwd()
     source = os.path.join(cwd, source)
     if options.use_listing_file:
         self.listing_file = replace_suffix(source, ".lis")
     if options.output_file:
         self.c_file = os.path.join(cwd, options.output_file)
     else:
         if options.cplus:
             self.c_file = replace_suffix(source, cplus_suffix)
         else:
             self.c_file = map_suffix(source, pyx_to_c_suffix, ".c")
Example #3
0
 def compile(self, source, options = None):
     # Compile a Pyrex implementation file in this context
     # and return a CompilationResult.
     if not options:
         options = default_options
     result = CompilationResult()
     cwd = os.getcwd()
     source = os.path.join(cwd, source)
     if options.use_listing_file:
         result.listing_file = replace_suffix(source, ".lis")
         Errors.open_listing_file(result.listing_file,
             echo_to_stderr = options.errors_to_stderr)
     else:
         Errors.open_listing_file(None)
     if options.output_file:
         result.c_file = os.path.join(cwd, options.output_file)
     else:
         if options.cplus:
             result.c_file = replace_suffix(source, cplus_suffix)
         else:
             result.c_file = map_suffix(source, pyx_to_c_suffix, ".c")
     module_name = self.extract_module_name(source)
     initial_pos = (source, 1, 0)
     def_scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
     imp_scope = ImplementationScope(def_scope)
     errors_occurred = False
     try:
         tree = self.parse(source, imp_scope, pxd = 0)
         tree.process_implementation(imp_scope, options, result)
     except CompileError:
         errors_occurred = True
     Errors.close_listing_file()
     result.num_errors = Errors.num_errors
     if result.num_errors > 0:
         errors_occurred = True
     if errors_occurred and result.c_file:
         try:
             st = os.stat(source)
             castrate_file(result.c_file, st)
         except EnvironmentError:
             pass
         result.c_file = None
     if result.c_file and not options.c_only and c_compile:
         result.object_file = c_compile(result.c_file,
             verbose_flag = options.show_version,
             cplus = options.cplus)
         if not options.obj_only and c_link:
             result.extension_file = c_link(result.object_file,
                 extra_objects = options.objects,
                 verbose_flag = options.show_version,
                 cplus = options.cplus)
     return result
Example #4
0
 def c_file_out_of_date(self, source_path):
     if debug_timestamps:
         print "Checking whether", source_path, "is out of date"
     c_path = map_suffix(source_path, pyx_to_c_suffix, ".c")
     if not os.path.exists(c_path):
         if debug_timestamps:
             print "...yes, c file doesn't exist"
         return 1
     c_time = modification_time(c_path)
     if file_newer_than(source_path, c_time):
         if debug_timestamps:
             print "...yes, newer than c file"
         return 1
     pos = [source_path]
     module_name = self.extract_module_name(source_path)
     pxd_path = self.find_pxd_file(module_name, pos)
     if pxd_path and file_newer_than(pxd_path, c_time):
         if debug_timestamps:
             print "...yes, pxd file newer than c file"
         return 1
     dep_path = replace_suffix(source_path, ".dep")
     if not os.path.exists(dep_path):
         if debug_timestamps:
             print "...yes, dep file does not exist"
         return 1
     for kind, name in self.read_dependency_file(source_path):
         if kind == "cimport":
             dep_path = self.find_pxd_file(name, pos)
         elif kind == "include":
             dep_path = self.search_include_directories(name, pos)
         else:
             continue
         if dep_path and file_newer_than(dep_path, c_time):
             if debug_timestamps:
                 print "...yes,", dep_path, "newer than c file"
             return 1
     if debug_timestamps:
         print "...no"
Example #5
0
 def c_file_out_of_date(self, source_path):
     if debug_timestamps:
         print "Checking whether", source_path, "is out of date"
     c_path = map_suffix(source_path, pyx_to_c_suffix, ".c")
     if not os.path.exists(c_path):
         if debug_timestamps:
             print "...yes, c file doesn't exist"
         return 1
     c_time = modification_time(c_path)
     if file_newer_than(source_path, c_time):
         if debug_timestamps:
             print "...yes, newer than c file"
         return 1
     pos = [source_path]
     module_name = self.extract_module_name(source_path)
     pxd_path = self.find_pxd_file(module_name, pos)
     if pxd_path and file_newer_than(pxd_path, c_time):
         if debug_timestamps:
             print "...yes, pxd file newer than c file"
         return 1
     dep_path = replace_suffix(source_path, ".dep")
     if not os.path.exists(dep_path):
         if debug_timestamps:
             print "...yes, dep file does not exist"
         return 1
     for kind, name in self.read_dependency_file(source_path):
         if kind == "cimport":
             dep_path = self.find_pxd_file(name, pos)
         elif kind == "include":
             dep_path = self.search_include_directories(name, pos)
         else:
             continue
         if dep_path and file_newer_than(dep_path, c_time):
             if debug_timestamps:
                 print "...yes,", dep_path, "newer than c file"
             return 1
     if debug_timestamps:
         print "...no"