]>
Commit | Line | Data |
---|---|---|
4710c53d | 1 | from distutils.core import Extension as _Extension\r |
2 | from distutils.core import Distribution as _Distribution\r | |
3 | \r | |
4 | def _get_unpatched(cls):\r | |
5 | """Protect against re-patching the distutils if reloaded\r | |
6 | \r | |
7 | Also ensures that no other distutils extension monkeypatched the distutils\r | |
8 | first.\r | |
9 | """\r | |
10 | while cls.__module__.startswith('setuptools'):\r | |
11 | cls, = cls.__bases__\r | |
12 | if not cls.__module__.startswith('distutils'):\r | |
13 | raise AssertionError(\r | |
14 | "distutils has already been patched by %r" % cls\r | |
15 | )\r | |
16 | return cls\r | |
17 | \r | |
18 | _Distribution = _get_unpatched(_Distribution)\r | |
19 | _Extension = _get_unpatched(_Extension)\r | |
20 | \r | |
21 | try:\r | |
22 | from Pyrex.Distutils.build_ext import build_ext\r | |
23 | except ImportError:\r | |
24 | have_pyrex = False\r | |
25 | else:\r | |
26 | have_pyrex = True\r | |
27 | \r | |
28 | \r | |
29 | class Extension(_Extension):\r | |
30 | """Extension that uses '.c' files in place of '.pyx' files"""\r | |
31 | \r | |
32 | if not have_pyrex:\r | |
33 | # convert .pyx extensions to .c\r | |
34 | def __init__(self,*args,**kw):\r | |
35 | _Extension.__init__(self,*args,**kw)\r | |
36 | sources = []\r | |
37 | for s in self.sources:\r | |
38 | if s.endswith('.pyx'):\r | |
39 | sources.append(s[:-3]+'c')\r | |
40 | else:\r | |
41 | sources.append(s)\r | |
42 | self.sources = sources\r | |
43 | \r | |
44 | class Library(Extension):\r | |
45 | """Just like a regular Extension, but built as a library instead"""\r | |
46 | \r | |
47 | import sys, distutils.core, distutils.extension\r | |
48 | distutils.core.Extension = Extension\r | |
49 | distutils.extension.Extension = Extension\r | |
50 | if 'distutils.command.build_ext' in sys.modules:\r | |
51 | sys.modules['distutils.command.build_ext'].Extension = Extension\r |