summaryrefslogtreecommitdiff
path: root/setup.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2022-02-04 16:21:58 -0700
committerCharles Harris <charlesr.harris@gmail.com>2022-02-05 10:05:54 -0700
commitdf8d1fd3c2077ca785b0948912162e03727ace6c (patch)
tree01dc1266363997d7fd8e181a2cfefaddaef9751c /setup.py
parentf32f47d58e51111a9c995b2f53dab0d0bdb1c927 (diff)
downloadnumpy-df8d1fd3c2077ca785b0948912162e03727ace6c.tar.gz
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.
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py29
1 files changed, 27 insertions, 2 deletions
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',):