Py3 install fix: keep original Py2 source modules of Cython alive during installation...
authorStefan Behnel <scoder@users.berlios.de>
Fri, 22 Oct 2010 15:01:45 +0000 (17:01 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 22 Oct 2010 15:01:45 +0000 (17:01 +0200)
setup.py

index 401a60fd825c36a9171c7c91518d614ff2035656..81d2eb65985ece6e66f0f6900ad8b83d34f169dd 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -106,12 +106,19 @@ def compile_cython_modules(profile=False):
                 )
 
         class build_ext(build_ext_orig):
+            # we must keep the original modules alive to make sure
+            # their code keeps working when we remove them from
+            # sys.modules
+            dead_modules = []
+
             def build_extensions(self):
                 # add path where 2to3 installed the transformed sources
                 # and make sure Python (re-)imports them from there
                 already_imported = [ module for module in sys.modules
                                      if module == 'Cython' or module.startswith('Cython.') ]
+                keep_alive = self.dead_modules.append
                 for module in already_imported:
+                    keep_alive(sys.modules[module])
                     del sys.modules[module]
                 sys.path.insert(0, os.path.join(source_root, self.build_lib))