1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 00:07:38 +00:00

setup.py: fix import error reporting for cythonize import, see #8208

Looks like borg's setup.py has hidden the real cause of a cythonize ImportError.

There are basically 2 cases:
- either there is no Cython installed, then the import fails because the module can not be found, or
- there is some issue within Cython and the import fails due to that.

It's important not to hide the real cause, especially if we run into case 2.

case 1 is kind of expected and frequent, case 2 is rare.
This commit is contained in:
Thomas Waldmann 2024-05-12 13:39:57 +02:00
parent 5e36ba789a
commit b067f0fba2
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -16,8 +16,11 @@
try: try:
from Cython.Build import cythonize from Cython.Build import cythonize
except ImportError: cythonize_import_error_msg = None
except ImportError as exc:
# either there is no Cython installed or there is some issue with it.
cythonize = None cythonize = None
cythonize_import_error_msg = "ImportError: " + str(exc)
sys.path += [os.path.dirname(__file__)] sys.path += [os.path.dirname(__file__)]
@ -80,7 +83,9 @@ def __init__(self, *args, **kwargs):
cython_c_files = [fn.replace(".pyx", ".c") for fn in cython_sources] cython_c_files = [fn.replace(".pyx", ".c") for fn in cython_sources]
if not on_rtd and not all(os.path.exists(path) for path in cython_c_files): if not on_rtd and not all(os.path.exists(path) for path in cython_c_files):
raise ImportError("The GIT version of Borg needs Cython. Install Cython or use a released version.") raise ImportError("The GIT version of Borg needs a working Cython. " +
"Install or fix Cython or use a released borg version. " +
"Importing cythonize failed with: " + cythonize_import_error_msg)
cmdclass = {"build_ext": build_ext, "sdist": Sdist} cmdclass = {"build_ext": build_ext, "sdist": Sdist}