diff --git a/setup.py b/setup.py index bdb59db1..f1042e70 100644 --- a/setup.py +++ b/setup.py @@ -10,13 +10,15 @@ """ +required_cython_version = '0.28' + no_cython_message = """ -You need to have Cython (>= 0.28) installed to build the snappy +You need to have Cython (>= %s) installed to build the snappy module since you're missing the autogenerated C/C++ files, e.g. - sudo python -m pip install "cython>=0.28" + sudo python -m pip install "cython>=%s" -""" +""" % (required_cython_version, required_cython_version) no_sphinx_message = """ You need to have Sphinx installed to rebuild the @@ -288,16 +290,23 @@ def run(self): from Cython.Build import cythonize from Cython import __version__ as cython_version have_cython = True -except ImportError: +except ImportError as e: have_cython = False + cython_import_error = e def replace_ext(file, new_ext): root, ext = os.path.splitext(file) return root + '.' + new_ext +def split_version(s : str): + return [int(x) for x in s.split('.')] + if have_cython: - if [int(x) for x in cython_version.split('.')[:2]] < [0, 28]: - raise ImportError + if split_version(cython_version) < split_version(required_cython_version): + raise ImportError( + 'Wrong cython version installed. ' + 'Required version: %s. Installed version: %s.' % ( + required_cython_version, cython_version)) if 'clean' not in sys.argv: cython_sources = [file for file in cython_sources if exists(file)] @@ -311,8 +320,10 @@ def replace_ext(file, new_ext): targets += [replace_ext(file, 'cpp') for file in cython_cpp_sources] for file in targets: if not exists(file): - raise ImportError(no_cython_message + - 'Missing Cythoned file: ' + file) + raise ImportError( + no_cython_message + + 'Missing Cythoned file: ' + file + + '\n[Cython import error: %r]' % cython_import_error) # We check manually which object files need to be rebuilt; distutils # is overly cautious and always rebuilds everything, which makes