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,26 +160,31 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
defines_for_module = []
else:
defines_for_module = defines
extensions.append(
Extension(module, sources = [pyx_source_file],
define_macros = defines_for_module,
depends = dep_files)
)
# XXX hack for '*.pyx ' sources
extensions.append(Extension(
module, sources=[pyx_source_file],
define_macros=defines_for_module,
depends=dep_files))
# XXX hack around setuptools quirk for '*.pyx' sources
extensions[-1].sources[0] = pyx_source_file
if sys.version_info[:2] != (3, 2):
from Cython.Distutils import build_ext
if sys.version_info[:2] == (3, 2):
# Python 3.2: can only run Cython *after* running 2to3
_defer_cython_compilation_in_py32(source_root, profile)
else:
if profile:
from Cython.Compiler.Options import directive_defaults
directive_defaults['profile'] = True
print("Enabled profiling for the Cython binary modules")
from Cython.Build import cythonize
extensions = cythonize(extensions)
setup_args['ext_modules'] = extensions
add_command_class("build_ext", build_ext)
else: # Python 3.2
def _defer_cython_compilation_in_py32(source_root, profile=False):
# Python 3.2: can only run Cython *after* running 2to3
# => hook into build_ext
from Cython.Distutils import build_ext as build_ext_orig
class build_ext(build_ext_orig):
......@@ -191,8 +196,10 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
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.') ]
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])
......@@ -205,7 +212,6 @@ def compile_cython_modules(profile=False, compile_more=False, cython_with_refnan
print("Enabled profiling for the Cython binary modules")
build_ext_orig.build_extensions(self)
setup_args['ext_modules'] = extensions
add_command_class("build_ext", build_ext)
......
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