|
14 | 14 | except ImportError: # pragma: no cover
|
15 | 15 | from pip._internal.download import PipSession
|
16 | 16 | from pip._internal.req.req_file import parse_requirements
|
17 |
| -from pip._internal.utils.compat import stdlib_pkgs |
18 |
| -from pip._internal.metadata import get_default_environment, get_environment |
19 |
| -from pip._internal.metadata.pkg_resources import Distribution as _Dist |
20 |
| -from pip._vendor.pkg_resources import Distribution |
| 17 | +try: |
| 18 | + from pip._internal.utils.misc import get_installed_distributions |
| 19 | +except ImportError: # pip>=21.3 |
| 20 | + from pip._internal.utils.compat import stdlib_pkgs |
| 21 | + from pip._internal.metadata import get_default_environment, get_environment |
| 22 | + from pip._internal.metadata.pkg_resources import Distribution as _Dist |
| 23 | + from pip._vendor.pkg_resources import Distribution |
| 24 | + |
| 25 | + # get_installed_distributions was removed in pip 21.3. |
| 26 | + # This is a copy from pip. |
| 27 | + # See |
| 28 | + # https://github.com/pypa/pip/commit/d051a00fc57037104fca85ad8ebf2cdbd1e32d24#diff-058e40cb3a9ea705f655937e48f3a053f5dc7c500b7f1b2aae76e9bd673faf64. |
| 29 | + # |
| 30 | + # This is mocked in all tests (unfortunately) and so we do not cover this |
| 31 | + # function. |
| 32 | + def get_installed_distributions( |
| 33 | + local_only: bool = True, |
| 34 | + skip: Container[str] = stdlib_pkgs, |
| 35 | + include_editables: bool = True, |
| 36 | + editables_only: bool = False, |
| 37 | + user_only: bool = False, |
| 38 | + paths: Optional[List[str]] = None, |
| 39 | + ) -> List[Distribution]: # pragma: no cover |
| 40 | + """Return a list of installed Distribution objects. |
| 41 | +
|
| 42 | + Left for compatibility until direct pkg_resources uses are refactored |
| 43 | + out. |
| 44 | + """ |
| 45 | + if paths is None: |
| 46 | + env = get_default_environment() |
| 47 | + else: |
| 48 | + env = get_environment(paths) |
21 | 49 |
|
22 |
| -log = logging.getLogger(__name__) |
| 50 | + dists = env.iter_installed_distributions( |
| 51 | + local_only=local_only, |
| 52 | + skip=skip, |
| 53 | + include_editables=include_editables, |
| 54 | + editables_only=editables_only, |
| 55 | + user_only=user_only, |
| 56 | + ) |
| 57 | + return [cast(_Dist, dist)._dist for dist in dists] |
23 | 58 |
|
24 | 59 |
|
25 |
| -# get_installed_distributions was removed in pip 21.3. |
26 |
| -# This is a copy from pip. |
27 |
| -# See |
28 |
| -# https://github.com/pypa/pip/commit/d051a00fc57037104fca85ad8ebf2cdbd1e32d24#diff-058e40cb3a9ea705f655937e48f3a053f5dc7c500b7f1b2aae76e9bd673faf64. |
29 |
| -# |
30 |
| -# This is mocked in all tests (unfortunately) and so we do not cover this |
31 |
| -# function. |
32 |
| -def get_installed_distributions( |
33 |
| - local_only: bool = True, |
34 |
| - skip: Container[str] = stdlib_pkgs, |
35 |
| - include_editables: bool = True, |
36 |
| - editables_only: bool = False, |
37 |
| - user_only: bool = False, |
38 |
| - paths: Optional[List[str]] = None, |
39 |
| - ) -> List[Distribution]: # pragma: no cover |
40 |
| - """Return a list of installed Distribution objects. |
41 |
| -
|
42 |
| - Left for compatibility until direct pkg_resources uses are refactored out. |
43 |
| - """ |
44 |
| - if paths is None: |
45 |
| - env = get_default_environment() |
46 |
| - else: |
47 |
| - env = get_environment(paths) |
48 |
| - |
49 |
| - dists = env.iter_installed_distributions( |
50 |
| - local_only=local_only, |
51 |
| - skip=skip, |
52 |
| - include_editables=include_editables, |
53 |
| - editables_only=editables_only, |
54 |
| - user_only=user_only, |
55 |
| - ) |
56 |
| - return [cast(_Dist, dist)._dist for dist in dists] |
| 60 | +log = logging.getLogger(__name__) |
57 | 61 |
|
58 | 62 |
|
59 | 63 | class FoundModule:
|
|
0 commit comments