diff options
Diffstat (limited to 'tools/cythonize.py')
-rwxr-xr-x | tools/cythonize.py | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/tools/cythonize.py b/tools/cythonize.py index 6ef908958..9e2af840d 100755 --- a/tools/cythonize.py +++ b/tools/cythonize.py @@ -52,35 +52,39 @@ except NameError: # Rules # def process_pyx(fromfile, tofile): - try: - from Cython.Compiler.Version import version as cython_version - from distutils.version import LooseVersion - if LooseVersion(cython_version) < LooseVersion('0.19'): - raise Exception('Building %s requires Cython >= 0.19' % VENDOR) - - except ImportError: - pass - flags = ['--fast-fail'] if tofile.endswith('.cxx'): flags += ['--cplus'] try: + # try the cython in the installed python first (somewhat related to scipy/scipy#2397) + from Cython.Compiler.Version import version as cython_version + except ImportError: + # if that fails, use the one on the path, which might be the wrong version try: - r = subprocess.call(['cython'] + flags + ["-o", tofile, fromfile]) - if r != 0: - raise Exception('Cython failed') + # Try the one on the path as a last resort + subprocess.check_call( + ['cython'] + flags + ["-o", tofile, fromfile]) except OSError: - # There are ways of installing Cython that don't result in a cython - # executable on the path, see gh-2397. - r = subprocess.call([sys.executable, '-c', - 'import sys; from Cython.Compiler.Main import ' - 'setuptools_main as main; sys.exit(main())'] + flags + - ["-o", tofile, fromfile]) - if r != 0: - raise Exception('Cython failed') - except OSError: - raise OSError('Cython needs to be installed') + raise OSError('Cython needs to be installed') + else: + # check the version, and invoke through python + from distutils.version import LooseVersion + + # requiring the newest version on all pythons doesn't work, since + # we're relying on the version of the distribution cython. Add new + # versions as they become required for new python versions. + if sys.version_info[:2] < (3, 7): + required_version = LooseVersion('0.19') + else: + required_version = LooseVersion('0.28') + + if LooseVersion(cython_version) < required_version: + raise RuntimeError('Building {} requires Cython >= {}'.format( + VENDOR, required_version)) + subprocess.check_call( + [sys.executable, '-m', 'cython'] + flags + ["-o", tofile, fromfile]) + def process_tempita_pyx(fromfile, tofile): import npy_tempita as tempita |