Commit a811c089 authored by Jason R. Coombs's avatar Jason R. Coombs

Detect Cython later in the build process, allowing the library to be specified...

Detect Cython later in the build process, allowing the library to be specified in setup_requires. Fixes #288.
parent c1d71724
...@@ -2,6 +2,30 @@ ...@@ -2,6 +2,30 @@
CHANGES CHANGES
======= =======
----
18.0
----
* Dropped support for builds with Pyrex. Only Cython is supported.
* Issue #288: Detect Cython later in the build process, after
``setup_requires`` dependencies are resolved.
Projects backed by Cython can now be readily built
with a ``setup_requires`` dependency. For example::
ext = setuptools.Extension('mylib', ['src/CythonStuff.pyx', 'src/CStuff.c'])
setuptools.setup(
...
ext_modules=[ext],
setup_requires=['cython'],
)
For compatibility with older versions of setuptools, packagers should
still include ``src/CythonMod.c`` in the source distributions or
require that Cython be present before building source distributions.
However, for systems with this build of setuptools, Cython will be
downloaded on demand.
------ ------
17.1.1 17.1.1
------ ------
......
...@@ -11,8 +11,8 @@ import itertools ...@@ -11,8 +11,8 @@ import itertools
from setuptools.extension import Library from setuptools.extension import Library
try: try:
# Attempt to use Pyrex for building extensions, if available # Attempt to use Cython for building extensions, if available
from Pyrex.Distutils.build_ext import build_ext as _build_ext from Cython.Distutils.build_ext import build_ext as _build_ext
except ImportError: except ImportError:
_build_ext = _du_build_ext _build_ext = _du_build_ext
...@@ -42,7 +42,6 @@ elif os.name != 'nt': ...@@ -42,7 +42,6 @@ elif os.name != 'nt':
if_dl = lambda s: s if have_rtld else '' if_dl = lambda s: s if have_rtld else ''
class build_ext(_build_ext): class build_ext(_build_ext):
def run(self): def run(self):
"""Build extensions in build directory, then copy if --inplace""" """Build extensions in build directory, then copy if --inplace"""
...@@ -74,15 +73,6 @@ class build_ext(_build_ext): ...@@ -74,15 +73,6 @@ class build_ext(_build_ext):
if ext._needs_stub: if ext._needs_stub:
self.write_stub(package_dir or os.curdir, ext, True) self.write_stub(package_dir or os.curdir, ext, True)
if _build_ext is not _du_build_ext and not hasattr(_build_ext,
'pyrex_sources'):
# Workaround for problems using some Pyrex versions w/SWIG and/or 2.4
def swig_sources(self, sources, *otherargs):
# first do any Pyrex processing
sources = _build_ext.swig_sources(self, sources) or sources
# Then do any actual SWIG stuff on the remainder
return _du_build_ext.swig_sources(self, sources, *otherargs)
def get_ext_filename(self, fullname): def get_ext_filename(self, fullname):
filename = _build_ext.get_ext_filename(self, fullname) filename = _build_ext.get_ext_filename(self, fullname)
if fullname in self.ext_map: if fullname in self.ext_map:
...@@ -176,6 +166,7 @@ class build_ext(_build_ext): ...@@ -176,6 +166,7 @@ class build_ext(_build_ext):
return _build_ext.get_export_symbols(self, ext) return _build_ext.get_export_symbols(self, ext)
def build_extension(self, ext): def build_extension(self, ext):
ext._convert_pyx_sources_to_lang()
_compiler = self.compiler _compiler = self.compiler
try: try:
if isinstance(ext, Library): if isinstance(ext, Library):
......
...@@ -12,35 +12,34 @@ _Extension = _get_unpatched(distutils.core.Extension) ...@@ -12,35 +12,34 @@ _Extension = _get_unpatched(distutils.core.Extension)
msvc9_support.patch_for_specialized_compiler() msvc9_support.patch_for_specialized_compiler()
def have_pyrex(): def _have_cython():
""" """
Return True if Cython or Pyrex can be imported. Return True if Cython can be imported.
""" """
pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext' cython_impls = 'Cython.Distutils.build_ext',
for pyrex_impl in pyrex_impls: for cython_impl in cython_impls:
try: try:
# from (pyrex_impl) import build_ext # from (cython_impl) import build_ext
__import__(pyrex_impl, fromlist=['build_ext']).build_ext __import__(cython_impl, fromlist=['build_ext']).build_ext
return True return True
except Exception: except Exception:
pass pass
return False return False
# for compatibility
have_pyrex = _have_cython
class Extension(_Extension): class Extension(_Extension):
"""Extension that uses '.c' files in place of '.pyx' files""" """Extension that uses '.c' files in place of '.pyx' files"""
def __init__(self, *args, **kw):
_Extension.__init__(self, *args, **kw)
self._convert_pyx_sources_to_lang()
def _convert_pyx_sources_to_lang(self): def _convert_pyx_sources_to_lang(self):
""" """
Replace sources with .pyx extensions to sources with the target Replace sources with .pyx extensions to sources with the target
language extension. This mechanism allows language authors to supply language extension. This mechanism allows language authors to supply
pre-converted sources but to prefer the .pyx sources. pre-converted sources but to prefer the .pyx sources.
""" """
if have_pyrex(): if _have_cython():
# the build has Cython, so allow it to compile the .pyx files # the build has Cython, so allow it to compile the .pyx files
return return
lang = self.language or '' lang = self.language or ''
......
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