Commit 3d404fd3 authored by Jason R. Coombs's avatar Jason R. Coombs

Refactor to use lookups and consolidate behaviors.

parent 77eeb77f
...@@ -66,14 +66,14 @@ def do_override(): ...@@ -66,14 +66,14 @@ def do_override():
class DistutilsMetaFinder: class DistutilsMetaFinder:
def find_spec(self, fullname, path, target=None): def find_spec(self, fullname, path, target=None):
self._disable_for_pip(fullname, path) if path is not None:
return
if path is not None or fullname != "distutils":
return None
return self.get_distutils_spec() method_name = 'spec_for_{fullname}'.format(**locals())
method = getattr(self, method_name, lambda: None)
return method()
def get_distutils_spec(self): def spec_for_distutils(self):
import importlib.util import importlib.util
class DistutilsLoader(importlib.util.abc.Loader): class DistutilsLoader(importlib.util.abc.Loader):
...@@ -86,17 +86,13 @@ class DistutilsMetaFinder: ...@@ -86,17 +86,13 @@ class DistutilsMetaFinder:
return importlib.util.spec_from_loader('distutils', DistutilsLoader()) return importlib.util.spec_from_loader('distutils', DistutilsLoader())
def _disable_for_pip(self, fullname, path): def spec_for_pip(self):
""" """
Ensure stdlib distutils when running under pip. Ensure stdlib distutils when running under pip.
See pypa/pip#8761 for rationale. See pypa/pip#8761 for rationale.
""" """
if path is not None or fullname != "pip":
return
# pip is being imported the first time.
clear_distutils() clear_distutils()
self.get_distutils_spec = lambda: None self.spec_for_distutils = lambda: None
DISTUTILS_FINDER = DistutilsMetaFinder() DISTUTILS_FINDER = DistutilsMetaFinder()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment