Skip to content

Commit ac25d94

Browse files
vagrantaholmberg
authored andcommitted
relax Cython req, make build work with old setuptools
see diff for explanation of old setuptools issue PYTHON-396
1 parent cda3f0b commit ac25d94

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

setup.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,25 @@ def __init__(self, ext):
178178
build_concurrency = int(os.environ.get('CASS_DRIVER_BUILD_CONCURRENCY', '0'))
179179

180180

181+
class NoPatchExtension(Extension):
182+
183+
# Older versions of setuptools.extension has a static flag which is set False before our
184+
# setup_requires lands Cython. It causes our *.pyx sources to be renamed to *.c in
185+
# the initializer.
186+
# The other workaround would be to manually generate sources, but that bypasses a lot
187+
# of the niceness cythonize embodies (setup build dir, conditional build, etc).
188+
# Newer setuptools does not have this problem because it checks for cython dynamically.
189+
# https://bitbucket.org/pypa/setuptools/commits/714c3144e08fd01a9f61d1c88411e76d2538b2e4
190+
191+
def __init__(self, *args, **kwargs):
192+
# bypass the patched init if possible
193+
if Extension.__bases__:
194+
base, = Extension.__bases__
195+
base.__init__(self, *args, **kwargs)
196+
else:
197+
Extension.__init__(self, *args, **kwargs)
198+
199+
181200
class build_extensions(build_ext):
182201

183202
error_message = """
@@ -279,7 +298,9 @@ def _setup_extensions(self):
279298
for m in cython_candidates],
280299
nthreads=build_concurrency,
281300
exclude_failures=True))
282-
self.extensions.extend(cythonize("cassandra/*.pyx", nthreads=build_concurrency))
301+
302+
self.extensions.extend(cythonize(NoPatchExtension("*", ["cassandra/*.pyx"], extra_compile_args=compile_args),
303+
nthreads=build_concurrency))
283304
except Exception:
284305
sys.stderr.write("Failed to cythonize one or more modules. These will not be compiled as extensions (optional).\n")
285306

@@ -297,7 +318,7 @@ def run_setup(extensions):
297318
kw['ext_modules'] = [Extension('DUMMY', [])] # dummy extension makes sure build_ext is called for install
298319

299320
if try_cython:
300-
kw['setup_requires'] = ['Cython >=0.21']
321+
kw['setup_requires'] = ['Cython>=0.20']
301322

302323
dependencies = ['six >=1.6']
303324

0 commit comments

Comments
 (0)