Skip to content

Commit 336e136

Browse files
committed
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.
1 parent 464568d commit 336e136

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

_distutils_hack/__init__.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,36 @@ def spec_for_pip(self):
136136
"""
137137
if self.pip_imported_during_build():
138138
return
139-
if self.is_get_pip():
140-
return
141139
clear_distutils()
142140
self.spec_for_distutils = lambda: None
143141

142+
def spec_for_setuptools(self):
143+
"""
144+
get-pip imports setuptools solely for the purpose of
145+
determining if it's installed. In this case, provide
146+
a stubbed spec to represent setuptools being present
147+
without invoking any behavior.
148+
149+
Workaround for pypa/get-pip#137.
150+
"""
151+
if not self.is_get_pip():
152+
return
153+
154+
import importlib
155+
156+
class StubbedLoader(importlib.abc.Loader):
157+
158+
def create_module(self, spec):
159+
import types
160+
return types.ModuleType('setuptools')
161+
162+
def exec_module(self, module):
163+
pass
164+
165+
return importlib.util.spec_from_loader(
166+
'setuptools', StubbedLoader(),
167+
)
168+
144169
@classmethod
145170
def pip_imported_during_build(cls):
146171
"""

0 commit comments

Comments
 (0)