Skip to content

Commit

Permalink
Merge pull request #2381 from pypa/bugfix/2355-keep-distutils-patched…
Browse files Browse the repository at this point in the history
…-when-pip-imported-during-build

When pip is imported as part of a build, leave distutils patched.
  • Loading branch information
jaraco authored Sep 4, 2020
2 parents 54af685 + 7c07fec commit 6952ae8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,22 @@ def spec_for_pip(self):
Ensure stdlib distutils when running under pip.
See pypa/pip#8761 for rationale.
"""
if self.pip_imported_during_build():
return
clear_distutils()
self.spec_for_distutils = lambda: None

@staticmethod
def pip_imported_during_build():
"""
Detect if pip is being imported in a build script. Ref #2355.
"""
import traceback
return any(
frame.f_globals['__file__'].endswith('setup.py')
for frame, line in traceback.walk_stack(None)
)


DISTUTILS_FINDER = DistutilsMetaFinder()

Expand Down
1 change: 1 addition & 0 deletions changelog.d/2355.change.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When pip is imported as part of a build, leave distutils patched.

0 comments on commit 6952ae8

Please sign in to comment.