Skip to content

Commit

Permalink
Avoid _distutils_hack.remove_shim on Python >= 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Jun 12, 2023
1 parent b545fc7 commit 5ae8b5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def spec_for_pip(self):
Ensure stdlib distutils when running under pip.
See pypa/pip#8761 for rationale.
"""
if self.pip_imported_during_build():
if self.pip_imported_during_build() or sys.version_info >= (3, 12):
return
clear_distutils()
self.spec_for_distutils = lambda: None
Expand Down Expand Up @@ -208,14 +208,21 @@ def __enter__(self):
insert_shim()

def __exit__(self, exc, value, tb):
remove_shim()
_remove_shim()


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


def remove_shim():
if sys.version_info < (3, 12):
# DistutilsMetaFinder should not be disabled in Python >= 3.12

def remove_shim():
_remove_shim()


def _remove_shim():
try:
sys.meta_path.remove(DISTUTILS_FINDER)
except ValueError:
Expand Down
2 changes: 1 addition & 1 deletion setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def hide_setuptools():
"""
_distutils_hack = sys.modules.get('_distutils_hack', None)
if _distutils_hack is not None:
_distutils_hack.remove_shim()
_distutils_hack._remove_shim()

modules = filter(_needs_hiding, sys.modules)
_clear_modules(modules)
Expand Down

0 comments on commit 5ae8b5b

Please sign in to comment.