Skip to content

Commit 7c07fec

Browse files
committed
When pip is imported as part of a build, leave distutils patched. Fixes #2355.
1 parent a60ba76 commit 7c07fec

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

_distutils_hack/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,22 @@ def spec_for_pip(self):
9292
Ensure stdlib distutils when running under pip.
9393
See pypa/pip#8761 for rationale.
9494
"""
95+
if self.pip_imported_during_build():
96+
return
9597
clear_distutils()
9698
self.spec_for_distutils = lambda: None
9799

100+
@staticmethod
101+
def pip_imported_during_build():
102+
"""
103+
Detect if pip is being imported in a build script. Ref #2355.
104+
"""
105+
import traceback
106+
return any(
107+
frame.f_globals['__file__'].endswith('setup.py')
108+
for frame, line in traceback.walk_stack(None)
109+
)
110+
98111

99112
DISTUTILS_FINDER = DistutilsMetaFinder()
100113

changelog.d/2355.change.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
When pip is imported as part of a build, leave distutils patched.

0 commit comments

Comments
 (0)