I was looking through my pip list and cleaning all my third party modules when I came across a module named 'distutils_hack'. I don't remember installing this, is this something I should be concerned about? The version I was using was Python 3.9.
It's used by setuptools to replace the stdlib distutils with setuptools' bundled distutils library.
Quoting ncoghlan from pypa/setuptools#417 on why this is necessary:
While CPython as a whole has many contributors, we don't have many folks contributing to
distutilsany more - folks need build tools that let them target currently deployed versions of Python, whichsetuptoolsprovides, butdistutilsreally doesn't.So the challenge for pypa/packaging-problems#127 is as follows:
- assume that in some future version of Python (3.9? 3.10? 4.0? We dunno yet)
distutilsis no longer in the standard library per se, but is instead bundled the way we bundlepip(i.e. by installing it from a wheel at Python installation time).- eventually, for new Python versions (where
distutilsisn't in the standard library), we'd like the "real" distutils code to live insetuptools, and the code you get when you doimport distutilsto just be a backward compatibility shim that aliases thesetuptoolscomponents into the right place- however, for old Python versions (where
distutilsis still in the standard library), thensetuptoolswill still need to do its monkeypatching magic to allow plain distutils projects to emit the installation database metadata and to be built as wheel archivesThe scope of the eventual
distutils-compatshim probably wouldn't need to be the full distutils API, but it wouldn't be the empty set either.So @jaraco's suggestion sounds like a reasonable starting point to me: give
setuptoolsits own pre-patched copy ofdistutilsso it can work on adistutils-free copy of Python, without providing an importabledistutilsfacade.Building a suitable facade (with a
setuptoolsdependency) would then be part of removingdistutilsfrom the standard library.
Here is where you can find the module's source code: https://github.com/pypa/setuptools/blob/main/_distutils_hack/__init__.py