Skip to content

Commit

Permalink
MAINT: Raise RuntimeError if setuptools version is too recent.
Browse files Browse the repository at this point in the history
NumPy does not build with setuptools versions greater than '60.0.0'.
Check the version when setuptools is imported in setup.py and raise
a RuntimeError if the version is too recent. That way we avoid people
opening issues when their build fails for that reason.

Closes #20692.
  • Loading branch information
charris committed Jan 11, 2022
1 parent 8f87be6 commit eb6be7c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions setup.py
Expand Up @@ -80,6 +80,10 @@
# so that it is in sys.modules
import numpy.distutils.command.sdist
import setuptools
if int(setuptools.__version__.split('.')[0]) >= 60:
raise RuntimeError(
"Setuptools version is '{}', version < '60.0.0' is required. "
"See pyproject.toml".format(setuptools.__version__))

# Initialize cmdclass from versioneer
from numpy.distutils.core import numpy_cmdclass
Expand Down

5 comments on commit eb6be7c

@mgorny
Copy link
Contributor

@mgorny mgorny commented on eb6be7c Jan 14, 2022

Choose a reason for hiding this comment

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

Wouldn't it be sufficient to fail when vendored distutils is used? Setuptools 60+ supports using SETUPTOOLS_USE_DISTUTILS=stdlib to avoid this kind of issues without forcing the whole system to use buggy unmaintained setuptools versions.

@mattip
Copy link
Member

@mattip mattip commented on eb6be7c Jan 16, 2022

Choose a reason for hiding this comment

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

How could we detect that?

@mgorny
Copy link
Contributor

@mgorny mgorny commented on eb6be7c Jan 16, 2022

Choose a reason for hiding this comment

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

Something alike:

default_distutils = "local" if int(setuptools.__version__.split('.')[0]) >= 60 else "stdlib"
if os.environ.get("SETUPTOOLS_USE_DISTUTILS", default_distutils) == "local":
    ...

@mattip
Copy link
Member

@mattip mattip commented on eb6be7c Jan 16, 2022

Choose a reason for hiding this comment

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

Ahh. I was hoping for something that would check that distutils is actually the one from the stdlib.

@seberg
Copy link
Member

@seberg seberg commented on eb6be7c Jan 16, 2022

Choose a reason for hiding this comment

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

Would it be possible to check __file__ or __module__ to find out if it is monkeypatched?

Please sign in to comment.