Skip to content

Commit 4d82a05

Browse files
committed
Fix commands on pip 21.2.1
This new version of pip has a new object type for packages - no longer are they just dictionaries.
1 parent 498b9e0 commit 4d82a05

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

pip_check_reqs/find_extra_reqs.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,32 @@ def find_extra_reqs(options, requirements_filename):
2121
installed_files = {}
2222
all_pkgs = (pkg.project_name for pkg in get_installed_distributions())
2323
for package in search_packages_info(all_pkgs):
24-
log.debug('installed package: %s (at %s)', package['name'],
25-
package['location'])
26-
for package_file in package.get('files', []) or []:
24+
if isinstance(package, dict):
25+
package_name = package['name']
26+
package_location = package['location']
27+
package_files = package.get('files', []) or []
28+
else:
29+
package_name = package.name
30+
package_location = package.location
31+
package_files = package.files or []
32+
33+
log.debug('installed package: %s (at %s)', package_name,
34+
package_location)
35+
for package_file in package_files:
2736
path = os.path.realpath(
28-
os.path.join(package['location'], package_file),
37+
os.path.join(package_location, package_file),
2938
)
30-
installed_files[path] = package['name']
39+
installed_files[path] = package_name
3140
package_path = common.is_package_file(path)
3241
if package_path:
3342
# we've seen a package file so add the bare package directory
3443
# to the installed list as well as we might want to look up
3544
# a package by its directory path later
36-
installed_files[package_path] = package['name']
45+
installed_files[package_path] = package_name
3746

3847
# 3. match imported modules against those packages
3948
used = collections.defaultdict(list)
49+
4050
for modname, info in used_modules.items():
4151
# probably standard library if it's not in the files list
4252
if info.filename in installed_files:

pip_check_reqs/find_missing_reqs.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,28 @@ def find_missing_reqs(options, requirements_filename):
2828
installed_files = {}
2929
all_pkgs = (pkg.project_name for pkg in get_installed_distributions())
3030
for package in search_packages_info(all_pkgs):
31-
log.debug('installed package: %s (at %s)', package['name'],
32-
package['location'])
33-
for package_file in package.get('files', []) or []:
31+
if isinstance(package, dict):
32+
package_name = package['name']
33+
package_location = package['location']
34+
package_files = package.get('files', []) or []
35+
else:
36+
package_name = package.name
37+
package_location = package.location
38+
package_files = package.files or []
39+
40+
log.debug('installed package: %s (at %s)', package_name,
41+
package_location)
42+
for package_file in package_files:
3443
path = os.path.realpath(
35-
os.path.join(package['location'], package_file),
44+
os.path.join(package_location, package_file),
3645
)
37-
installed_files[path] = package['name']
46+
installed_files[path] = package_name
3847
package_path = common.is_package_file(path)
3948
if package_path:
4049
# we've seen a package file so add the bare package directory
4150
# to the installed list as well as we might want to look up
4251
# a package by its directory path later
43-
installed_files[package_path] = package['name']
52+
installed_files[package_path] = package_name
4453

4554
# 3. match imported modules against those packages
4655
used = collections.defaultdict(list)

0 commit comments

Comments
 (0)