summaryrefslogtreecommitdiff
path: root/_distutils_hack/__init__.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-01-10 17:16:25 -0500
committerJason R. Coombs <jaraco@jaraco.com>2022-01-10 17:22:57 -0500
commitca6152aad37eea45257ac7d86111c48026c49598 (patch)
treeee3967d56c203d81ea0864e80ecd27c79dd0242f /_distutils_hack/__init__.py
parent464568d64469fb1ca9794ef26fe2288f16c15598 (diff)
downloadpython-setuptools-git-bugfix/2993-redux.tar.gz
Instead of detecting 'get-pip' during the import of pip, detect the attempt to 'import setuptools' during 'get-pip', and in that case, stub the import to signal the presence of setuptools. Ref #3022. Fixes #2993.bugfix/2993-redux
Diffstat (limited to '_distutils_hack/__init__.py')
-rw-r--r--_distutils_hack/__init__.py29
1 files changed, 27 insertions, 2 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py
index ab462f95..0108d854 100644
--- a/_distutils_hack/__init__.py
+++ b/_distutils_hack/__init__.py
@@ -136,11 +136,36 @@ class DistutilsMetaFinder:
"""
if self.pip_imported_during_build():
return
- if self.is_get_pip():
- return
clear_distutils()
self.spec_for_distutils = lambda: None
+ def spec_for_setuptools(self):
+ """
+ get-pip imports setuptools solely for the purpose of
+ determining if it's installed. In this case, provide
+ a stubbed spec to represent setuptools being present
+ without invoking any behavior.
+
+ Workaround for pypa/get-pip#137.
+ """
+ if not self.is_get_pip():
+ return
+
+ import importlib
+
+ class StubbedLoader(importlib.abc.Loader):
+
+ def create_module(self, spec):
+ import types
+ return types.ModuleType('setuptools')
+
+ def exec_module(self, module):
+ pass
+
+ return importlib.util.spec_from_loader(
+ 'setuptools', StubbedLoader(),
+ )
+
@classmethod
def pip_imported_during_build(cls):
"""