Commit 64da2480 authored by Stefan Behnel's avatar Stefan Behnel

clean up extension building in setup.py: clarify what's Py3.2-specific and use...

clean up extension building in setup.py: clarify what's Py3.2-specific and use cythonize() instead of Cython.Distutils
parent b43f5a18
...@@ -160,53 +160,59 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan ...@@ -160,53 +160,59 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
defines_for_module = [] defines_for_module = []
else: else:
defines_for_module = defines defines_for_module = defines
extensions.append( extensions.append(Extension(
Extension(module, sources = [pyx_source_file], module, sources=[pyx_source_file],
define_macros = defines_for_module, define_macros=defines_for_module,
depends = dep_files) depends=dep_files))
) # XXX hack around setuptools quirk for '*.pyx' sources
# XXX hack for '*.pyx ' sources
extensions[-1].sources[0] = pyx_source_file extensions[-1].sources[0] = pyx_source_file
if sys.version_info[:2] != (3, 2): if sys.version_info[:2] == (3, 2):
from Cython.Distutils import build_ext # Python 3.2: can only run Cython *after* running 2to3
_defer_cython_compilation_in_py32(source_root, profile)
else:
if profile: if profile:
from Cython.Compiler.Options import directive_defaults from Cython.Compiler.Options import directive_defaults
directive_defaults['profile'] = True directive_defaults['profile'] = True
print("Enabled profiling for the Cython binary modules") print("Enabled profiling for the Cython binary modules")
setup_args['ext_modules'] = extensions from Cython.Build import cythonize
add_command_class("build_ext", build_ext) extensions = cythonize(extensions)
else: # Python 3.2 setup_args['ext_modules'] = extensions
from Cython.Distutils import build_ext as build_ext_orig
class build_ext(build_ext_orig): def _defer_cython_compilation_in_py32(source_root, profile=False):
# we must keep the original modules alive to make sure # Python 3.2: can only run Cython *after* running 2to3
# their code keeps working when we remove them from # => hook into build_ext
# sys.modules from Cython.Distutils import build_ext as build_ext_orig
dead_modules = []
class build_ext(build_ext_orig):
def build_extensions(self): # we must keep the original modules alive to make sure
# add path where 2to3 installed the transformed sources # their code keeps working when we remove them from
# and make sure Python (re-)imports them from there # sys.modules
already_imported = [ module for module in sys.modules dead_modules = []
if module == 'Cython' or module.startswith('Cython.') ]
keep_alive = self.dead_modules.append def build_extensions(self):
for module in already_imported: # add path where 2to3 installed the transformed sources
keep_alive(sys.modules[module]) # and make sure Python (re-)imports them from there
del sys.modules[module] already_imported = [
sys.path.insert(0, os.path.join(source_root, self.build_lib)) module for module in sys.modules
if module == 'Cython' or module.startswith('Cython.')
if profile: ]
from Cython.Compiler.Options import directive_defaults keep_alive = self.dead_modules.append
directive_defaults['profile'] = True for module in already_imported:
print("Enabled profiling for the Cython binary modules") keep_alive(sys.modules[module])
build_ext_orig.build_extensions(self) del sys.modules[module]
sys.path.insert(0, os.path.join(source_root, self.build_lib))
setup_args['ext_modules'] = extensions
add_command_class("build_ext", build_ext) if profile:
from Cython.Compiler.Options import directive_defaults
directive_defaults['profile'] = True
print("Enabled profiling for the Cython binary modules")
build_ext_orig.build_extensions(self)
add_command_class("build_ext", build_ext)
cython_profile = '--cython-profile' in sys.argv cython_profile = '--cython-profile' in sys.argv
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment