diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-09-04 09:56:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-04 09:56:33 -0400 |
| commit | 6952ae898ebfeaa9fe0d21ebd20f1a2e23ad07dc (patch) | |
| tree | 31834e868a760b8551b2b1d295a221615ca6800a | |
| parent | 54af685555b1ebce9a27bb95f94a58423554ec5f (diff) | |
| parent | 7c07fec3f02093bf048a1192473ab0736211e47e (diff) | |
| download | python-setuptools-git-6952ae898ebfeaa9fe0d21ebd20f1a2e23ad07dc.tar.gz | |
Merge pull request #2381 from pypa/bugfix/2355-keep-distutils-patched-when-pip-imported-during-build
When pip is imported as part of a build, leave distutils patched.
| -rw-r--r-- | _distutils_hack/__init__.py | 13 | ||||
| -rw-r--r-- | changelog.d/2355.change.rst | 1 |
2 files changed, 14 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() diff --git a/changelog.d/2355.change.rst b/changelog.d/2355.change.rst new file mode 100644 index 00000000..d17435f5 --- /dev/null +++ b/changelog.d/2355.change.rst @@ -0,0 +1 @@ +When pip is imported as part of a build, leave distutils patched. |
