~ibmcharmers/charms/xenial/ibm-cinder-storwize-svc/trunk

« back to all changes in this revision

Viewing changes to .tox/py35/lib/python3.5/site-packages/setuptools/extension.py

  • Committer: Ankammarao
  • Date: 2017-03-06 05:11:42 UTC
  • Revision ID: achittet@in.ibm.com-20170306051142-dpg27z4es1k56hfn
Marked tests folder executable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import re
 
2
import functools
 
3
import distutils.core
 
4
import distutils.errors
 
5
import distutils.extension
 
6
 
 
7
from six.moves import map
 
8
 
 
9
from .monkey import get_unpatched
 
10
 
 
11
 
 
12
def _have_cython():
 
13
    """
 
14
    Return True if Cython can be imported.
 
15
    """
 
16
    cython_impl = 'Cython.Distutils.build_ext'
 
17
    try:
 
18
        # from (cython_impl) import build_ext
 
19
        __import__(cython_impl, fromlist=['build_ext']).build_ext
 
20
        return True
 
21
    except Exception:
 
22
        pass
 
23
    return False
 
24
 
 
25
 
 
26
# for compatibility
 
27
have_pyrex = _have_cython
 
28
 
 
29
_Extension = get_unpatched(distutils.core.Extension)
 
30
 
 
31
 
 
32
class Extension(_Extension):
 
33
    """Extension that uses '.c' files in place of '.pyx' files"""
 
34
 
 
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)
 
40
 
 
41
    def _convert_pyx_sources_to_lang(self):
 
42
        """
 
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.
 
46
        """
 
47
        if _have_cython():
 
48
            # the build has Cython, so allow it to compile the .pyx files
 
49
            return
 
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))
 
54
 
 
55
 
 
56
class Library(Extension):
 
57
    """Just like a regular Extension, but built as a library instead"""