4
import distutils.errors
5
import distutils.extension
7
from six.moves import map
9
from .monkey import get_unpatched
14
Return True if Cython can be imported.
16
cython_impl = 'Cython.Distutils.build_ext'
18
# from (cython_impl) import build_ext
19
__import__(cython_impl, fromlist=['build_ext']).build_ext
27
have_pyrex = _have_cython
29
_Extension = get_unpatched(distutils.core.Extension)
32
class Extension(_Extension):
33
"""Extension that uses '.c' files in place of '.pyx' files"""
35
def __init__(self, name, sources, *args, **kw):
36
# The *args is needed for compatibility as calls may use positional
37
# arguments. py_limited_api may be set only via keyword.
38
self.py_limited_api = kw.pop("py_limited_api", False)
39
_Extension.__init__(self, name, sources, *args, **kw)
41
def _convert_pyx_sources_to_lang(self):
43
Replace sources with .pyx extensions to sources with the target
44
language extension. This mechanism allows language authors to supply
45
pre-converted sources but to prefer the .pyx sources.
48
# the build has Cython, so allow it to compile the .pyx files
50
lang = self.language or ''
51
target_ext = '.cpp' if lang.lower() == 'c++' else '.c'
52
sub = functools.partial(re.sub, '.pyx$', target_ext)
53
self.sources = list(map(sub, self.sources))
56
class Library(Extension):
57
"""Just like a regular Extension, but built as a library instead"""