8
8
9
9
from packaging .utils import canonicalize_name
10
10
from pip ._internal .commands .show import search_packages_info
11
- # Between different versions of pip the location of PipSession has changed.
12
- try :
13
- from pip ._internal .network .session import PipSession
14
- except ImportError : # pragma: no cover
15
- from pip ._internal .download import PipSession
11
+ from pip ._internal .network .session import PipSession
12
+ from pip ._internal .req .constructors import install_req_from_line
16
13
from pip ._internal .req .req_file import parse_requirements
17
14
18
15
from pip_check_reqs import common
@@ -34,26 +31,21 @@ def find_missing_reqs(options, requirements_filename):
34
31
)
35
32
36
33
for package in search_packages_info (all_pkgs ):
37
- if isinstance (package , dict ): # pragma: no cover
38
- package_name = package ['name' ]
39
- package_location = package ['location' ]
40
- package_files = package .get ('files' , []) or []
41
- else : # pragma: no cover
42
- package_name = package .name
43
- package_location = package .location
44
- package_files = []
45
- for item in (package .files or []):
46
- here = pathlib .Path ('.' ).resolve ()
47
- item_location_rel = (pathlib .Path (package_location ) / item )
48
- item_location = item_location_rel .resolve ()
49
- try :
50
- relative_item_location = item_location .relative_to (here )
51
- except ValueError :
52
- # Ideally we would use Pathlib.is_relative_to rather than
53
- # checking for a ValueError, but that is only available in
54
- # Python 3.9+.
55
- relative_item_location = item_location
56
- package_files .append (str (relative_item_location ))
34
+ package_name = package .name
35
+ package_location = package .location
36
+ package_files = []
37
+ for item in (package .files or []):
38
+ here = pathlib .Path ('.' ).resolve ()
39
+ item_location_rel = (pathlib .Path (package_location ) / item )
40
+ item_location = item_location_rel .resolve ()
41
+ try :
42
+ relative_item_location = item_location .relative_to (here )
43
+ except ValueError :
44
+ # Ideally we would use Pathlib.is_relative_to rather than
45
+ # checking for a ValueError, but that is only available in
46
+ # Python 3.9+.
47
+ relative_item_location = item_location
48
+ package_files .append (str (relative_item_location ))
57
49
58
50
log .debug ('installed package: %s (at %s)' , package_name ,
59
51
package_location )
@@ -89,16 +81,9 @@ def find_missing_reqs(options, requirements_filename):
89
81
requirements_filename ,
90
82
session = PipSession (),
91
83
):
92
- try :
93
- requirement_name = requirement .name
94
- # The type of "requirement" changed between pip versions.
95
- # We exclude the "except" from coverage so that on any pip version we
96
- # can report 100% coverage.
97
- except AttributeError : # pragma: no cover
98
- from pip ._internal .req .constructors import install_req_from_line
99
- requirement_name = install_req_from_line (
100
- requirement .requirement ,
101
- ).name
84
+ requirement_name = install_req_from_line (
85
+ requirement .requirement ,
86
+ ).name
102
87
103
88
log .debug ('found requirement: %s' , requirement_name )
104
89
explicit .add (canonicalize_name (requirement_name ))
0 commit comments