Skip to content

Commit 75f73ff

Browse files
committed
Skip Cythonizing for clean command
This commit changes our current cythonization logic so that we don't convert cython files to C files on an invocation of the clean command. Should the need arise, it will also be easy in the furture to skip Cythonization for other commands.
1 parent a44de30 commit 75f73ff

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

setup.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import print_function
33

44
from setuptools import setup
5+
from setuptools import Distribution
56
from setuptools.command.sdist import sdist
67
from setuptools.extension import Extension
78
import platform
@@ -109,6 +110,41 @@ def run(self):
109110
os.remove(SKIP_CYTHON_FILE)
110111

111112

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+
112148
# detect support
113149
def main_file(module):
114150
return Extension('gssapi.raw.%s' % module,
@@ -161,9 +197,6 @@ def gssapi_modules(lst):
161197
# add in any present enum extension files
162198
res.extend(ENUM_EXTS)
163199

164-
if SOURCE_EXT == 'pyx':
165-
res = cythonize(res)
166-
167200
return res
168201

169202
long_desc = re.sub('\.\. role:: \w+\(code\)\s*\n\s*.+', '',
@@ -195,6 +228,7 @@ def gssapi_modules(lst):
195228
'Topic :: Security',
196229
'Topic :: Software Development :: Libraries :: Python Modules'
197230
],
231+
distclass=GSSAPIDistribution,
198232
cmdclass={'sdist': sdist_gssapi},
199233
ext_modules=gssapi_modules([
200234
main_file('misc'),

0 commit comments

Comments
 (0)