Skip to content

Commit

Permalink
Merge pull request #3023 from pypa/bugfix/2993-redux
Browse files Browse the repository at this point in the history
Instead of detecting 'get-pip' during the import of pip, detect 'import setuptools'
  • Loading branch information
jaraco committed Jan 11, 2022
2 parents 857d777 + ca6152a commit a1ec345
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
29 changes: 27 additions & 2 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions changelog.d/2993.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In _distutils_hack, for get-pip, simulate existence of setuptools.

0 comments on commit a1ec345

Please sign in to comment.