summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2015-10-02 15:50:15 +0200
committerStefan Behnel <stefan_ml@behnel.de>2015-10-02 15:50:15 +0200
commit64da2480e88d8cd3eec2b9a5d2922307623c3cd5 (patch)
tree3373e6b46a8adac8159b312ccf67fa9f3fa33ffc
parentb43f5a1833e6dffd7cbc661bcca943baa4824833 (diff)
downloadcython-64da2480e88d8cd3eec2b9a5d2922307623c3cd5.tar.gz
clean up extension building in setup.py: clarify what's Py3.2-specific and use cythonize() instead of Cython.Distutils
-rwxr-xr-xsetup.py86
1 files changed, 46 insertions, 40 deletions
diff --git a/setup.py b/setup.py
index fb6241f71..48747f3f0 100755
--- a/setup.py
+++ b/setup.py
@@ -160,53 +160,59 @@ 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")
- setup_args['ext_modules'] = extensions
- add_command_class("build_ext", build_ext)
-
- else: # Python 3.2
- from Cython.Distutils import build_ext as build_ext_orig
-
- 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))
-
- 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)
-
- setup_args['ext_modules'] = extensions
- add_command_class("build_ext", build_ext)
+ from Cython.Build import cythonize
+ extensions = cythonize(extensions)
+
+ setup_args['ext_modules'] = extensions
+
+
+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):
+ # 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))
+
+ 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