Skip to content

Commit 9960d93

Browse files
Merge branch 'master' into fix_skip_incompatible
2 parents c8c637a + 6b4dca7 commit 9960d93

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Release History
55
2.3.1
66

77
- Fixed `--skip-incompatible` skipping other requirements too.
8+
- Support pip >= 21.3
89

910
2.3.0
1011

pip_check_reqs/common.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import os
66
import re
7+
from typing import Container, Optional, List, cast
78

89
from packaging.utils import canonicalize_name
910
from packaging.markers import Marker
@@ -13,10 +14,48 @@
1314
except ImportError: # pragma: no cover
1415
from pip._internal.download import PipSession
1516
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
1621

1722
log = logging.getLogger(__name__)
1823

1924

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]
57+
58+
2059
class FoundModule:
2160
def __init__(self, modname, filename, locations=None):
2261
self.modname = modname

pip_check_reqs/find_extra_reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
from packaging.utils import canonicalize_name
99
from pip._internal.commands.show import search_packages_info
10-
from pip._internal.utils.misc import get_installed_distributions
1110
from pip_check_reqs import common
11+
from pip_check_reqs.common import get_installed_distributions
1212

1313
log = logging.getLogger(__name__)
1414

pip_check_reqs/find_missing_reqs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
except ImportError: # pragma: no cover
1414
from pip._internal.download import PipSession
1515
from pip._internal.req.req_file import parse_requirements
16-
from pip._internal.utils.misc import get_installed_distributions
1716

1817
from pip_check_reqs import common
18+
from pip_check_reqs.common import get_installed_distributions
1919

2020
log = logging.getLogger(__name__)
2121

0 commit comments

Comments
 (0)