From e74ad055a31e39d01924e45c408971b37f399b06 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 22 Oct 2010 17:01:45 +0200 Subject: [PATCH] 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 --- setup.py | 7 +++++++ 1 file changed, 7 insertions(+) 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)) -- 2.26.2