Skip to content

Commit f649aea

Browse files
committed
Fix support for pip versions pre-21.3
1 parent f0716ac commit f649aea

File tree

3 files changed

+46
-38
lines changed

3 files changed

+46
-38
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Release History
33
---------------
44

5+
2.3.2
6+
7+
- Fixed support for pip < 21.3
8+
59
2.3.1
610

711
- Fixed `--skip-incompatible` skipping other requirements too.

pip_check_reqs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.3.1'
1+
__version__ = '2.3.2'

pip_check_reqs/common.py

Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,50 @@
1414
except ImportError: # pragma: no cover
1515
from pip._internal.download import PipSession
1616
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)
2149

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]
2358

2459

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__)
5761

5862

5963
class FoundModule:

0 commit comments

Comments
 (0)