Skip to content

Fix import errors if setuptools is too old #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions pytensor/link/c/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
from setuptools.errors import CompileError as BaseCompileError
try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment?

Copy link
Contributor

@maresb maresb Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to instead add a warning here. I'm tracking down the various relevant setuptools versions to cite.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ferrine, @twiecki, I added a warning. Does this look helpful?

In [1]: import pytensor
~/repos/pytensor/pytensor/link/c/exceptions.py:14: UserWarning: You appear to be using an ancient
version of setuptools: v57.4.0. Please upgrade to at least v59.0.0. Support for this version of
setuptools is provisionary and may be removed without warning in the future.
  warnings.warn(

In [2]:

I'm not sure what the dangling warnings.warn( is about, but I'm not sure we should care.

from setuptools.errors import CompileError as BaseCompileError
except ImportError:
import warnings
from distutils.errors import CompileError as BaseCompileError # type: ignore
from importlib.metadata import version

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

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

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


class CompileError(BaseCompileError):
"""This custom `Exception` prints compilation errors with their original
formatting.
"""
class CompileError(BaseCompileError): # pyright: ignore
"""Custom `Exception` prints compilation errors with their original formatting."""

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