File tree Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Expand file tree Collapse file tree 1 file changed +11
-8
lines changed Original file line number Diff line number Diff line change 33import re
44import importlib
55import warnings
6- import inspect
76
87
98is_pypy = '__pypy__' in sys .builtin_module_names
@@ -67,7 +66,9 @@ def do_override():
6766
6867class DistutilsMetaFinder :
6968 def find_spec (self , fullname , path , target = None ):
70- if path is not None or fullname != "distutils" or self ._bypass ():
69+ self ._disable_for_pip (fullname , path )
70+
71+ if path is not None or fullname != "distutils" :
7172 return None
7273
7374 return self .get_distutils_spec ()
@@ -85,15 +86,17 @@ def exec_module(self, module):
8586
8687 return importlib .util .spec_from_loader ('distutils' , DistutilsLoader ())
8788
88- def _bypass (self ):
89+ def _disable_for_pip (self , fullname , path ):
8990 """
90- Suppress the import of distutils from setuptools when running under pip.
91+ Ensure stdlib distutils when running under pip.
9192 See pypa/pip#8761 for rationale.
9293 """
93- return any (
94- level .frame .f_globals ['__name__' ].startswith ('pip.' )
95- for level in inspect .stack (context = False )
96- )
94+ if path is not None or fullname != "pip" :
95+ return
96+
97+ # pip is being imported the first time.
98+ clear_distutils ()
99+ self .get_distutils_spec = lambda : None
97100
98101
99102DISTUTILS_FINDER = DistutilsMetaFinder ()
You can’t perform that action at this time.
0 commit comments