setuptools: [BUG] release v65.6.0 breaks packages downstream due to removal of `distutils.log.Log`

setuptools version

65.6.0

Python version

Python 3.10

OS

Ubuntu

Additional environment information

No response

Description

The distutils.log.Log class was removed in https://github.com/pypa/setuptools/commit/74652cabdeaacadc76ccf126563bed8ee2ccf3ef. This causes popular packages downstream, such as numpy, to fail: see https://github.com/numpy/numpy/issues/22623

Expected behavior

The module distutils.log module was not officially marked as deprecated even though https://github.com/pypa/setuptools/commit/74652cabdeaacadc76ccf126563bed8ee2ccf3ef added to the docstring that the module is Retained for compatibility and should not be used.. It would be great if the removed class could be reinstated and a deprecation pathway be provided.

How to Reproduce

  1. pip install setuptools==65.6.0
  2. from numpy.distutils import Log

Output

In [4]: from numpy.distutils import Log
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-4-f8e71815afcd> in <module>
----> 1 from numpy.distutils import Log

~/.virtualenvs/aiida_dev/lib/python3.9/site-packages/numpy/distutils/__init__.py in <module>
     22 # Must import local ccompiler ASAP in order to get
     23 # customized CCompiler.spawn effective.
---> 24 from . import ccompiler
     25 from . import unixccompiler
     26 

~/.virtualenvs/aiida_dev/lib/python3.9/site-packages/numpy/distutils/ccompiler.py in <module>
     18 from distutils.version import LooseVersion
     19 
---> 20 from numpy.distutils import log
     21 from numpy.distutils.exec_command import (
     22     filepath_from_subprocess_output, forward_bytes_to_stdout

~/.virtualenvs/aiida_dev/lib/python3.9/site-packages/numpy/distutils/log.py in <module>
      2 import sys
      3 from distutils.log import *  # noqa: F403
----> 4 from distutils.log import Log as old_Log
      5 from distutils.log import _global_log
      6 

ImportError: cannot import name 'Log' from 'distutils.log' (/home/sph/.virtualenvs/aiida_dev/lib/python3.9/site-packages/setuptools/_distutils/log.py)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 36
  • Comments: 24 (4 by maintainers)

Commits related to this issue

Most upvoted comments

export SETUPTOOLS_USE_DISTUTILS=stdlib appears to be another workaround, which allowed me then to build/install scipy==1.4.1 on ARM (where there are no prebuilt binaries).

@bentheiii 's alternative above of pip install --no-build-isolation scipy==1.4.1 after pinning back setuptools was the only other way I got to work so far.

I’ve cut a release 65.6.2 with the fix. Sorry it took so long to get a remedy out. That was mainly my fault. Huge thanks to abravalheri for multiple fixes and validation work.

Thank you all for reporting the problem, in https://github.com/pypa/distutils/pull/192 I am proposing a backfill for the appreciation of pypa/distutils maintainers. If accepted, this patch will find its way into setuptools.

Note that is still something that needs to be debated in pypa/distutils, since in https://github.com/pypa/setuptools/issues/2372 the numpy maintainers agreed with setuptools strategy of making SETUPTOOLS_USE_DISTUTILS=local the default behaviour.

Also note that the recommendation from the numpy team for everyone using numpy.distutils is the following:

numpy.distutils is deprecated since NumPy 1.23.0, as a result of the deprecation of distutils itself. It will be removed for Python >= 3.12. For older Python versions it will remain present. It is recommended to use setuptools < 60.0 for those Python versions. For more details, see: https://numpy.org/devdocs/reference/distutils_status_migration.html

  • Initially setuptools integration tests included numpy, however since numpy is pinning the setuptools version used, this integration test also became impractical and was removed.

There should probably be a distinction between building numpy (with pinned setuptools) in CI, versus building a carefully crafted test case that depends on numpy and setuptools, and does from numpy.distutils import ....

The latter is what really needs to be tested here in order to make sure that yet more projects using numpy.distutils are operational.

Running into this for statsmodels==0.13.0 and numpy==1.22.0

@bentheiii I’m running into this from numpy 1.19.4 also. what do I need to downgrade 1.1.15 to? we are supposed to be on setuptools==53.0.0 but still running into this somehow started recently…

Thanks @jaraco @abravalheri !

(FWIW @tulbureandreit , I’m also building Docker images, though using pip rather than poetry. Setting the env var with ENV is what I’m doing so that it applies to any and all pip installs.)

This actually breaks just importing numpy.distutils altogether:

In [2]: import numpy.distutils
---------------------------------------------------------------------------
ImportError
...
~/38venv/lib/python3.8/site-packages/numpy/distutils/log.py in <module>
      2 import sys
      3 from distutils.log import *  # noqa: F403
----> 4 from distutils.log import Log as old_Log
      5 from distutils.log import _global_log
      6 

ImportError: cannot import name 'Log' from 'distutils.log' (~/38venv/lib/python3.8/site-packages/setuptools/_distutils/log.py)