There's an effort underway to move the functionality of distutils into Setuptools and other libraries, with a goal to remove distutils from the standard library.
Re:
(Though replacing distutils with setuptools wherever possible is worthwhile irrespective of the distutils injection strategy.)
setuptoolswill be the canonical implementation of "distutils" in the future. Some of thedistutilshierarchy already is duplicated insetuptools(like commands), the parts that are likely to remain supported will likely move into thesetuptools(I suspect that will include things like exceptions) namespace, and some stuff that is no longer necessary will be deprecated and removed.If you need something from the
distutilsnamespace and it's not available insetuptools, continue to use it until we provide an alternative (I would say "raise an issue" but I am not sure if we're going to just do a bulk migration or not), but if there's already an equivalent insetuptools, switching over to usingsetuptoolsnow is the best thing you can do (and you _should_ report any issues you encounter when doing this).
...
setuptoolsis not exposing its version ofdistutilsassetuptools.distutils(and to the extent that it exists under thesetuptoolsnamespace, that location is not necessarily stable).setuptoolsreplaces the top-leveldistutilsmodule with its own version ofdistutils, soimport distutilspulls the version fromsetuptools.This is one phase of an ongoing project to remove
distutilsfrom the standard library (and probably eventually retire the project entirely in favor ofsetuptools).
Here's where we're using disutils:
| File | Use | Replacement |
| - | - | - |
| Tests/test_image_access.py and setup.py | from distutils import ccompiler, sysconfig | #4809, #4814, #4817 |
| Tests/test_imagefont.py | distutils.version.StrictVersion | packaging.version.parse #4797 |
| setup.py | from distutils.command.build_ext import build_ext | from setuptools.command.build_ext import build_ext #4829 |
| setup.py | from distutils import cygwinccompiler | #4890 |
I'm not certain that we need to remove from distutils import cygwinccompiler. Some thoughts.
The import of cygwinccompiler was added in #4019, to resolve #4018 - the Python distutils in the MinGW environment was using "gcc --print-prog-name ld" when looking for ld.
When we moved the MinGW job from AppVeyor to GitHub Actions, this code actually stopped being run by our CIs - the problem doesn't occur on GHA.
setuptools doesn't use gcc to try and find the path. So once distutils is no more, this code can be safely removed.
If we wanted to remove it now, I think there are only two alternatives. Either add code to ensure that setuptools distutils is used, rather than Python distutils, or if a user ever reports it, suggest that they investigate how to correctly connect gcc with ld.
I've created https://github.com/msys2/MINGW-packages/issues/6744 to see if the fallback behaviour can be incorporated into the MinGW patches.
I'm not certain that we need to remove
from distutils import cygwinccompiler. Some thoughts.The import of
cygwinccompilerwas added in #4019, to resolve #4018 - the Python distutils in the MinGW environment was using "gcc --print-prog-name ld" when looking for ld.When we moved the MinGW job from AppVeyor to GitHub Actions, this code actually stopped being run by our CIs - the problem doesn't occur on GHA.
setuptools doesn't use gcc to try and find the path. So once distutils is no more, this code can be safely removed.
If we wanted to remove it now, I think there are only two alternatives. Either add code to ensure that setuptools distutils is used, rather than Python distutils, or if a user ever reports it, suggest that they investigate how to correctly connect gcc with ld.
While working on #4890, I've just realized the actual cause of #4018, and the proper fix. The issue was that AppVeyor was missing the MSYSTEM=MINGW32 envvar, and getting confused by the default MSYSTEM=MSYS2.
After adding the envvar in my branch https://github.com/nulano/Pillow/compare/master...nulano:mingw-test2, the build passes on AppVeyor.
After removing MSYSTEM=MINGW32 again in my branch https://github.com/nulano/Pillow/compare/mingw-test2...nulano:mingw-test3, the build fails again.
I've therefore removed the GCC workaround in #4890.