Skip to content

Commit

Permalink
Instead of detecting 'get-pip' during the import of pip, detect the a…
Browse files Browse the repository at this point in the history
…ttempt to 'import setuptools' during 'get-pip', and in that case, stub the import to signal the presence of setuptools. Ref #3022. Fixes #2993.
  • Loading branch information
jaraco committed Jan 10, 2022
1 parent 464568d commit 336e136
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions _distutils_hack/__init__.py
Expand Up @@ -136,11 +136,36 @@ def spec_for_pip(self):
"""
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):
"""
Expand Down

0 comments on commit 336e136

Please sign in to comment.