diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-09-04 09:29:21 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-09-04 09:30:01 -0400 |
commit | 7c07fec3f02093bf048a1192473ab0736211e47e (patch) | |
tree | a565b090a26e4c47c3f006fd8b7f76f305fff87a /_distutils_hack | |
parent | a60ba76395353974f5bb51ad1c117d7239ed5032 (diff) | |
download | python-setuptools-git-7c07fec3f02093bf048a1192473ab0736211e47e.tar.gz |
When pip is imported as part of a build, leave distutils patched. Fixes #2355.
Diffstat (limited to '_distutils_hack')
-rw-r--r-- | _distutils_hack/__init__.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index 504c4ac0..c31edfed 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -92,9 +92,22 @@ class DistutilsMetaFinder: 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() |