Skip to content

Commit

Permalink
cython requirement checks: having central place for required version …
Browse files Browse the repository at this point in the history
…and display cython import error for easier debugging.
  • Loading branch information
unhyperbolic committed May 16, 2024
1 parent 29470e3 commit 70a4fab
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand All @@ -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
Expand Down

0 comments on commit 70a4fab

Please sign in to comment.