diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2020-08-14 19:32:18 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-08-14 19:38:53 -0400 |
| commit | be7a0a31a116f6df9bef616ef1adef72b9d0d48d (patch) | |
| tree | 5695604293857ae8cd0974c470aabc6f26fd4d7b /_distutils_hack/__init__.py | |
| parent | 4837f218ea05a304880f8448e27fe0affad3a1a5 (diff) | |
| download | python-setuptools-git-be7a0a31a116f6df9bef616ef1adef72b9d0d48d.tar.gz | |
Bypass .pth loader when distutils is loaded from pip. Workaround for pypa/pip#8761.
Diffstat (limited to '_distutils_hack/__init__.py')
| -rw-r--r-- | _distutils_hack/__init__.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/_distutils_hack/__init__.py b/_distutils_hack/__init__.py index 814ee97e..2d358c37 100644 --- a/_distutils_hack/__init__.py +++ b/_distutils_hack/__init__.py @@ -3,6 +3,7 @@ import os import re import importlib import warnings +import inspect is_pypy = '__pypy__' in sys.builtin_module_names @@ -66,7 +67,7 @@ def do_override(): class DistutilsMetaFinder: def find_spec(self, fullname, path, target=None): - if path is not None or fullname != "distutils": + if path is not None or fullname != "distutils" or self._bypass(): return None return self.get_distutils_spec() @@ -84,6 +85,16 @@ class DistutilsMetaFinder: return importlib.util.spec_from_loader('distutils', DistutilsLoader()) + def _bypass(self): + """ + Suppress the import of distutils from setuptools when running under pip. + See pypa/pip#8761 for rationale. + """ + return any( + level.frame.f_globals['__name__'].startswith('pip.') + for level in inspect.stack(context=False) + ) + DISTUTILS_FINDER = DistutilsMetaFinder() |
