[Pyrex] module name patch

Eric Huss e-huss at netmeridian.com
Wed May 24 00:56:06 UTC 2006


This is a patch that fixes an issue with pyrex modules inside a package.
The problem was that the __module__ attribute of classes was not getting
set (via __Pyx_CreateClass) to the full package module name.  Some things
like pychecker look at this and complain since they can't find the module.

-Eric
-------------- next part --------------
--- Pyrex/Compiler/Main.py.orig	Tue May 23 17:39:04 2006
+++ Pyrex/Compiler/Main.py	Tue May 23 17:47:54 2006
@@ -149,7 +149,7 @@
         name, _ = os.path.splitext(tail)
         return name
 
-    def compile(self, source, options = None):
+    def compile(self, source, options = None, name = None):
         # Compile a Pyrex implementation file in this context
         # and return a CompilationResult.
         if not options:
@@ -171,7 +171,10 @@
             else:
                 c_suffix = ".c"
             result.c_file = replace_suffix(source, c_suffix)
-        module_name = self.extract_module_name(source)
+        if name:
+            module_name = name
+        else:
+            module_name = self.extract_module_name(source)
         initial_pos = (source, 1, 0)
         scope = self.find_module(module_name, pos = initial_pos, need_pxd = 0)
         errors_occurred = False
@@ -255,7 +258,7 @@
         self.extension_file = None
 
 
-def compile(source, options = None, c_compile = 0, c_link = 0):
+def compile(source, options = None, c_compile = 0, c_link = 0, name = None):
     """
     compile(source, options = default_options)
     
@@ -270,7 +273,7 @@
     if c_link:
         options.obj_only = 0
     context = Context(options.include_path)
-    return context.compile(source, options)
+    return context.compile(source, options, name=name)
 
 #------------------------------------------------------------------------
 #
--- Pyrex/Distutils/build_ext.py.orig	Tue May 23 17:42:04 2006
+++ Pyrex/Distutils/build_ext.py	Tue May 23 17:42:10 2006
@@ -50,14 +50,19 @@
                 source = pyx
                 target = replace_suffix(source, suffix)
                 if newer(source, target) or self.force:
-                    self.pyrex_compile(source)
+                    self.pyrex_compile(source, extension)
 
         return [replace_suffix(src, suffix) for src in pyx_sources] + other_sources
 
-    def pyrex_compile(self, source):
+    def pyrex_compile(self, source, extension):
         options = CompilationOptions(default_options,
             include_path = self.include_dirs)
-        result = compile(source, options)
+        if extension:
+            name = extension.name
+        else:
+            # Older version of distutils.
+            name = None
+        result = compile(source, options, name=name)
         if result.num_errors <> 0:
             sys.exit(1)
 


More information about the Pyrex mailing list