From: Stefan Behnel Date: Fri, 22 Oct 2010 15:01:45 +0000 (+0200) Subject: Py3 install fix: keep original Py2 source modules of Cython alive during installation... X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=e74ad055a31e39d01924e45c408971b37f399b06;p=cython.git Py3 install fix: keep original Py2 source modules of Cython alive during installation when replacing them with 2to3-ed versions - we still need the build_ext stuff --- diff --git a/setup.py b/setup.py index 401a60fd..81d2eb65 100644 --- 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))