Skip to content

Commit e3097cc

Browse files
committed
debugging for new pip
1 parent 59372fe commit e3097cc

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

pip_check_reqs/find_missing_reqs.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import logging
33
import optparse
44
import os
5+
import pkg_resources
56
import sys
67

78
from packaging.utils import canonicalize_name
8-
from pip._internal.commands.show import search_packages_info
9+
#from pip._internal.commands.show import search_packages_info
910
from pip._internal.download import PipSession
1011
from pip._internal.req.req_file import parse_requirements
1112
from pip._internal.utils.misc import get_installed_distributions
@@ -15,6 +16,46 @@
1516
log = logging.getLogger(__name__)
1617

1718

19+
def search_packages_info(query):
20+
"""
21+
Gather details from installed distributions. Print distribution name,
22+
version, location, and installed files. Installed files requires a
23+
pip generated 'installed-files.txt' in the distributions '.egg-info'
24+
directory.
25+
"""
26+
installed = {}
27+
for p in pkg_resources.working_set:
28+
installed[canonicalize_name(p.project_name)] = p
29+
30+
query_names = [canonicalize_name(name) for name in query]
31+
32+
for dist in [installed[pkg] for pkg in query_names if pkg in installed]:
33+
package = {
34+
'name': dist.project_name,
35+
'version': dist.version,
36+
'location': dist.location,
37+
'requires': [dep.project_name for dep in dist.requires()],
38+
}
39+
file_list = None
40+
if isinstance(dist, pkg_resources.DistInfoDistribution):
41+
# RECORDs should be part of .dist-info metadatas
42+
if dist.has_metadata('RECORD'):
43+
lines = dist.get_metadata_lines('RECORD')
44+
paths = [l.split(',')[0] for l in lines]
45+
paths = [os.path.join(dist.location, p) for p in paths]
46+
file_list = [os.path.relpath(p, dist.location) for p in paths]
47+
else:
48+
# Otherwise use pip's log for .egg-info's
49+
if dist.has_metadata('installed-files.txt'):
50+
paths = dist.get_metadata_lines('installed-files.txt')
51+
paths = [os.path.join(dist.egg_info, p) for p in paths]
52+
file_list = [os.path.relpath(p, dist.location) for p in paths]
53+
54+
if file_list:
55+
package['files'] = sorted(file_list)
56+
yield package
57+
58+
1859
def find_missing_reqs(options):
1960
# 1. find files used by imports in the code (as best we can without
2061
# executing)

0 commit comments

Comments
 (0)