5 __all__ = ['install', 'NullFinder', 'Protocol']
9 from typing import Protocol
10 except ImportError: # pragma: no cover
11 from ..typing_extensions import Protocol # type: ignore
16 Class decorator for installation on sys.meta_path.
18 Adds the backport DistributionFinder to sys.meta_path and
19 attempts to disable the finder functionality of the stdlib
22 sys.meta_path.append(cls())
23 disable_stdlib_finder()
27 def disable_stdlib_finder():
29 Give the backport primacy for discovering path-based distributions
30 by monkey-patching the stdlib O_O.
32 See #91 for more background for rationale on this sketchy
38 finder, '__module__', None
39 ) == '_frozen_importlib_external' and hasattr(finder, 'find_distributions')
41 for finder in filter(matches, sys.meta_path): # pragma: nocover
42 del finder.find_distributions
47 A "Finder" (aka "MetaClassFinder") that never finds any modules,
48 but may find distributions.
52 def find_spec(*args, **kwargs):
55 # In Python 2, the import system requires finders
56 # to have a find_module() method, but this usage
57 # is deprecated in Python 3 in favor of find_spec().
58 # For the purposes of this finder (i.e. being present
59 # on sys.meta_path but having no other import
60 # system functionality), the two methods are identical.
61 find_module = find_spec
64 def pypy_partial(val):
66 Adjust for variable stacklevel on partial under PyPy.
70 is_pypy = platform.python_implementation() == 'PyPy'