Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instead of detecting 'get-pip' during the import of pip, detect 'import setuptools' #3023

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.