From df8d1fd3c2077ca785b0948912162e03727ace6c Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Fri, 4 Feb 2022 16:21:58 -0700 Subject: MAINT: Replace LooseVersion by _pep440. LooseVersion is provided by Python distutils, which is going away in 3.12. This PR vendors _pep440 from scipy and uses it as a replacement. Numpy distutils is not touched, replacing LooseVersion in that package was considered too risky, and numpy distutils will need to go away when Python distutils does. --- setup.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'setup.py') diff --git a/setup.py b/setup.py index 085b158ed..e8ac94174 100755 --- a/setup.py +++ b/setup.py @@ -207,7 +207,7 @@ def get_build_overrides(): """ from numpy.distutils.command.build_clib import build_clib from numpy.distutils.command.build_ext import build_ext - from distutils.version import LooseVersion + from numpy.compat import _pep440 def _needs_gcc_c99_flag(obj): if obj.compiler.compiler_type != 'unix': @@ -221,7 +221,7 @@ def get_build_overrides(): out = subprocess.run([cc, '-dumpversion'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) # -std=c99 is default from this version on - if LooseVersion(out.stdout) >= LooseVersion('5.0'): + if _pep440.parse(out.stdout) >= _pep440.Version('5.0'): return False return True @@ -242,6 +242,31 @@ def get_build_overrides(): def generate_cython(): + # Check Cython version + from numpy.compat import _pep440 + try: + # try the cython in the installed python first (somewhat related to + # scipy/scipy#2397) + import Cython + from Cython.Compiler.Version import version as cython_version + except ImportError as e: + # The `cython` command need not point to the version installed in the + # Python running this script, so raise an error to avoid the chance of + # using the wrong version of Cython. + msg = 'Cython needs to be installed in Python as a module' + raise OSError(msg) from e + else: + # Note: keep in sync with that in pyproject.toml + # Update for Python 3.10 + required_version = '0.29.24' + + if _pep440.parse(cython_version) < _pep440.Version(required_version): + cython_path = Cython.__file__ + msg = 'Building NumPy requires Cython >= {}, found {} at {}' + msg = msg.format(required_version, cython_version, cython_path) + raise RuntimeError(msg) + + # Process files cwd = os.path.abspath(os.path.dirname(__file__)) print("Cythonizing sources") for d in ('random',): -- cgit v1.2.1