Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / distribute-0.6.19-py2.7.egg / setuptools / extension.py @ 1a305335

History | View | Annotate | Download (1.25 KB)

1
from distutils.core import Extension as _Extension
2
from setuptools.dist import _get_unpatched
3
_Extension = _get_unpatched(_Extension)
4

    
5
# Prefer Cython to Pyrex
6
pyrex_impls = 'Cython.Distutils.build_ext', 'Pyrex.Distutils.build_ext'
7
for pyrex_impl in pyrex_impls:
8
        try:
9
                # from (pyrex_impl) import build_ext
10
                build_ext = __import__(pyrex_impl, fromlist=['build_ext']).build_ext
11
                break
12
        except:
13
                pass
14
have_pyrex = 'build_ext' in globals()
15

    
16

    
17
class Extension(_Extension):
18
    """Extension that uses '.c' files in place of '.pyx' files"""
19

    
20
    if not have_pyrex:
21
        # convert .pyx extensions to .c 
22
        def __init__(self,*args,**kw):
23
            _Extension.__init__(self,*args,**kw)
24
            sources = []
25
            for s in self.sources:
26
                if s.endswith('.pyx'):
27
                    sources.append(s[:-3]+'c')
28
                else:
29
                    sources.append(s)
30
            self.sources = sources
31

    
32
class Library(Extension):
33
    """Just like a regular Extension, but built as a library instead"""
34

    
35
import sys, distutils.core, distutils.extension
36
distutils.core.Extension = Extension
37
distutils.extension.Extension = Extension
38
if 'distutils.command.build_ext' in sys.modules:
39
    sys.modules['distutils.command.build_ext'].Extension = Extension
40