From b728bdad2a4fe29f2eedb8f37bdeefc1f60e756d Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Sun, 24 Jul 2022 12:42:54 +0100 Subject: [PATCH 1/2] Remove the setuptools-provided distutils hack, if using distutils This ensures that pip's imported copy of distutils comes from the standard library, if/when the hack needs to be used. --- src/pip/_internal/locations/_distutils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pip/_internal/locations/_distutils.py b/src/pip/_internal/locations/_distutils.py index aac821888d5..1b8b42606d7 100644 --- a/src/pip/_internal/locations/_distutils.py +++ b/src/pip/_internal/locations/_distutils.py @@ -3,6 +3,17 @@ # The following comment should be removed at some point in the future. # mypy: strict-optional=False +# If pip's going to use distutils, it should not be using the copy that setuptools +# might have injected into the environment. This is done by removing the injected +# shim, if it's injected. +# +# See https://github.com/pypa/pip/issues/8761 for the original discussion and +# rationale for why this is done within pip. +try: + __import__("_distutils_hack").remove_shim() +except ImportError: + pass + import logging import os import sys From a14f1412ce269cd0869f56b589e8e3209b7ac215 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 26 Jul 2022 19:35:13 +0100 Subject: [PATCH 2/2] :newspaper: --- news/11298.bugfix.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 news/11298.bugfix.rst diff --git a/news/11298.bugfix.rst b/news/11298.bugfix.rst new file mode 100644 index 00000000000..1f52404f3c7 --- /dev/null +++ b/news/11298.bugfix.rst @@ -0,0 +1,4 @@ +Ensure that things work correctly in environments where setuptools-injected +``distutils`` is available by default. This is done by cooperating with +setuptools' injection logic to ensure that pip uses the ``distutils`` from the +Python standard library instead.