Skip to content

Commit 718493c

Browse files
committed
Avoid _distutils_hack.remove_shim on Python >= 3.12 (#3952)
2 parents 2d7bf2b + e391a09 commit 718493c

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

_distutils_hack/__init__.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def spec_for_pip(self):
142142
Ensure stdlib distutils when running under pip.
143143
See pypa/pip#8761 for rationale.
144144
"""
145-
if self.pip_imported_during_build():
145+
if sys.version_info >= (3, 12) or self.pip_imported_during_build():
146146
return
147147
clear_distutils()
148148
self.spec_for_distutils = lambda: None
@@ -208,15 +208,20 @@ def __enter__(self):
208208
insert_shim()
209209

210210
def __exit__(self, exc, value, tb):
211-
remove_shim()
211+
_remove_shim()
212212

213213

214214
def insert_shim():
215215
sys.meta_path.insert(0, DISTUTILS_FINDER)
216216

217217

218-
def remove_shim():
218+
def _remove_shim():
219219
try:
220220
sys.meta_path.remove(DISTUTILS_FINDER)
221221
except ValueError:
222222
pass
223+
224+
225+
if sys.version_info < (3, 12):
226+
# DistutilsMetaFinder can only be disabled in Python < 3.12 (PEP 632)
227+
remove_shim = _remove_shim

changelog.d/3952.change.1.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Changed ``DistutilsMetaFinder`` to skip ``spec_for_pip`` on Python >= 3.12.

changelog.d/3952.change.2.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Removed ``_distutils_hack.remove_shim`` on Python >= 3.12
2+
(since ``distutils`` was removed from the standard library,
3+
``DistutilsMetaFinder`` cannot be disabled on Python >= 3.12).

setuptools/sandbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def hide_setuptools():
237237
"""
238238
_distutils_hack = sys.modules.get('_distutils_hack', None)
239239
if _distutils_hack is not None:
240-
_distutils_hack.remove_shim()
240+
_distutils_hack._remove_shim()
241241

242242
modules = filter(_needs_hiding, sys.modules)
243243
_clear_modules(modules)

0 commit comments

Comments
 (0)