From 7c07fec3f02093bf048a1192473ab0736211e47e Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 4 Sep 2020 09:29:21 -0400 Subject: When pip is imported as part of a build, leave distutils patched. Fixes #2355. --- _distutils_hack/__init__.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to '_distutils_hack/__init__.py') 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() -- cgit v1.2.1