|
2 | 2 | from __future__ import print_function
|
3 | 3 |
|
4 | 4 | from setuptools import setup
|
| 5 | +from setuptools import Distribution |
5 | 6 | from setuptools.command.sdist import sdist
|
6 | 7 | from setuptools.extension import Extension
|
7 | 8 | import platform
|
@@ -109,6 +110,41 @@ def run(self):
|
109 | 110 | os.remove(SKIP_CYTHON_FILE)
|
110 | 111 |
|
111 | 112 |
|
| 113 | +DONT_CYTHONIZE_FOR = ('clean',) |
| 114 | + |
| 115 | + |
| 116 | +class GSSAPIDistribution(Distribution, object): |
| 117 | + def run_command(self, command): |
| 118 | + self._last_run_command = command |
| 119 | + Distribution.run_command(self, command) |
| 120 | + |
| 121 | + @property |
| 122 | + def ext_modules(self): |
| 123 | + if SOURCE_EXT != 'pyx': |
| 124 | + return getattr(self, '_ext_modules', None) |
| 125 | + |
| 126 | + if getattr(self, '_ext_modules', None) is None: |
| 127 | + return None |
| 128 | + |
| 129 | + if getattr(self, '_last_run_command', None) in DONT_CYTHONIZE_FOR: |
| 130 | + return self._ext_modules |
| 131 | + |
| 132 | + if getattr(self, '_cythonized_ext_modules', None) is None: |
| 133 | + self._cythonized_ext_modules = cythonize(self._ext_modules) |
| 134 | + |
| 135 | + return self._cythonized_ext_modules |
| 136 | + |
| 137 | + @ext_modules.setter |
| 138 | + def ext_modules(self, mods): |
| 139 | + self._cythonized_ext_modules = None |
| 140 | + self._ext_modules = mods |
| 141 | + |
| 142 | + @ext_modules.deleter |
| 143 | + def ext_modules(self): |
| 144 | + del self._ext_modules |
| 145 | + del self._cythonized_ext_modules |
| 146 | + |
| 147 | + |
112 | 148 | # detect support
|
113 | 149 | def main_file(module):
|
114 | 150 | return Extension('gssapi.raw.%s' % module,
|
@@ -161,9 +197,6 @@ def gssapi_modules(lst):
|
161 | 197 | # add in any present enum extension files
|
162 | 198 | res.extend(ENUM_EXTS)
|
163 | 199 |
|
164 |
| - if SOURCE_EXT == 'pyx': |
165 |
| - res = cythonize(res) |
166 |
| - |
167 | 200 | return res
|
168 | 201 |
|
169 | 202 | long_desc = re.sub('\.\. role:: \w+\(code\)\s*\n\s*.+', '',
|
@@ -195,6 +228,7 @@ def gssapi_modules(lst):
|
195 | 228 | 'Topic :: Security',
|
196 | 229 | 'Topic :: Software Development :: Libraries :: Python Modules'
|
197 | 230 | ],
|
| 231 | + distclass=GSSAPIDistribution, |
198 | 232 | cmdclass={'sdist': sdist_gssapi},
|
199 | 233 | ext_modules=gssapi_modules([
|
200 | 234 | main_file('misc'),
|
|
0 commit comments