Skip to content

Commit c9159b2

Browse files
ferrinemaresb
andauthored
Fix import errors if setuptools is too old (#483)
* add fallback class * lint * Complain about ancient setuptools version * Add a hack to appease mypy * Tidy up --------- Co-authored-by: Ben Mares <[email protected]>
1 parent 7bb18f3 commit c9159b2

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

pytensor/link/c/exceptions.py

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
from setuptools.errors import CompileError as BaseCompileError
1+
try:
2+
from setuptools.errors import CompileError as BaseCompileError
3+
except ImportError:
4+
import warnings
5+
from distutils.errors import CompileError as BaseCompileError # type: ignore
6+
from importlib.metadata import version
27

8+
# These exception classes were made available in setuptools
9+
# since v59.0.0 via <https://github.com/pypa/setuptools/pull/2858>
10+
# in preparation for distutils deprecation. Complain loudly if they
11+
# are not available.
12+
setuptools_version = version("setuptools")
13+
warnings.warn(
14+
f"You appear to be using an ancient version of setuptools: "
15+
f"v{setuptools_version}. Please upgrade to at least v59.0.0. "
16+
f"Support for this version of setuptools is provisionary and "
17+
f"may be removed without warning in the future."
18+
)
319

4-
class MissingGXX(Exception):
5-
"""
6-
This error is raised when we try to generate c code,
7-
but g++ is not available.
820

9-
"""
21+
class MissingGXX(Exception):
22+
"""This error is raised when we try to generate c code, but g++ is not available."""
1023

1124

12-
class CompileError(BaseCompileError):
13-
"""This custom `Exception` prints compilation errors with their original
14-
formatting.
15-
"""
25+
class CompileError(BaseCompileError): # pyright: ignore
26+
"""Custom `Exception` prints compilation errors with their original formatting."""
1627

1728
def __str__(self):
1829
return self.args[0]

0 commit comments

Comments
 (0)