Skip to content

Commit 1caaca7

Browse files
authored
Merge pull request #18 from KarrLab/master
Updating for pip 10.0.1
2 parents 803052f + 5788bd7 commit 1caaca7

File tree

10 files changed

+65
-24
lines changed

10 files changed

+65
-24
lines changed

pip_check_reqs/__init__.py

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

pip_check_reqs/common.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
import imp
44
import logging
55
import os
6+
import pkg_resources
67
import re
78

89
from packaging.utils import canonicalize_name
9-
from pip.download import PipSession
10-
from pip.req import parse_requirements
10+
from pip._internal.download import PipSession
11+
from pip._internal.req.req_file import parse_requirements
1112

1213
log = logging.getLogger(__name__)
1314

@@ -155,3 +156,43 @@ def f(candidate, ignore_cfg=ignore_cfg):
155156
return True
156157
return False
157158
return f
159+
160+
161+
def search_packages_info(query):
162+
"""
163+
Gather details from installed distributions. Print distribution name,
164+
version, location, and installed files. Installed files requires a
165+
pip generated 'installed-files.txt' in the distributions '.egg-info'
166+
directory.
167+
"""
168+
installed = {}
169+
for p in pkg_resources.working_set:
170+
installed[canonicalize_name(p.project_name)] = p
171+
172+
query_names = [canonicalize_name(name) for name in query]
173+
174+
for dist in [installed[pkg] for pkg in query_names if pkg in installed]:
175+
package = {
176+
'name': dist.project_name,
177+
'version': dist.version,
178+
'location': dist.location,
179+
'requires': [dep.project_name for dep in dist.requires()],
180+
}
181+
file_list = None
182+
if isinstance(dist, pkg_resources.DistInfoDistribution):
183+
# RECORDs should be part of .dist-info metadatas
184+
if dist.has_metadata('RECORD'):
185+
lines = dist.get_metadata_lines('RECORD')
186+
paths = [l.split(',')[0] for l in lines]
187+
paths = [os.path.join(dist.location, p) for p in paths]
188+
file_list = [os.path.relpath(p, dist.location) for p in paths]
189+
else:
190+
# Otherwise use pip's log for .egg-info's
191+
if dist.has_metadata('installed-files.txt'):
192+
paths = dist.get_metadata_lines('installed-files.txt')
193+
paths = [os.path.join(dist.egg_info, p) for p in paths]
194+
file_list = [os.path.relpath(p, dist.location) for p in paths]
195+
196+
if file_list:
197+
package['files'] = sorted(file_list)
198+
yield package

pip_check_reqs/find_extra_reqs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import sys
66

77
from packaging.utils import canonicalize_name
8-
from pip.commands.show import search_packages_info
9-
from pip.utils import get_installed_distributions
10-
8+
#from pip._internal.commands.show import search_packages_info
9+
from pip._internal.utils.misc import get_installed_distributions
1110
from pip_check_reqs import common
11+
from pip_check_reqs.common import search_packages_info
1212

1313
log = logging.getLogger(__name__)
1414

pip_check_reqs/find_missing_reqs.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import sys
66

77
from packaging.utils import canonicalize_name
8-
from pip.commands.show import search_packages_info
9-
from pip.download import PipSession
10-
from pip.req import parse_requirements
11-
from pip.utils import get_installed_distributions
8+
#from pip._internal.commands.show import search_packages_info
9+
from pip._internal.download import PipSession
10+
from pip._internal.req.req_file import parse_requirements
11+
from pip._internal.utils.misc import get_installed_distributions
1212

1313
from pip_check_reqs import common
14+
from pip_check_reqs.common import search_packages_info
1415

1516
log = logging.getLogger(__name__)
1617

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
packaging
2-
pip>=6.0
2+
pip >= 10.0.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'Find packages that should or should not be in requirements for a '
2525
'project',
2626
long_description=long_description,
27-
url='https://github.com/r1chardj0n3s/pip-check-reqs',
27+
url='https://github.com/KarrLab/pip-check-reqs',
2828
author='Richard Jonees',
2929
author_email='[email protected]',
3030
license='MIT',

test-requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
coverage
22
pretend
3-
pytest
4-
pytest-capturelog
3+
pytest

tests/test_common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def __exit__(self, *args):
119119
pass
120120
monkeypatch.setattr(common, 'open', FakeFile, raising=False)
121121

122-
caplog.setLevel(logging.INFO)
122+
caplog.set_level(logging.INFO)
123123

124124
class options:
125125
paths = ['dummy']
@@ -142,7 +142,7 @@ def ignore_mods(module):
142142
assert result['ast'].locations == locs
143143

144144
if ignore_ham:
145-
assert caplog.records()[0].message == 'ignoring: ham.py'
145+
assert caplog.records[0].message == 'ignoring: ham.py'
146146

147147

148148
@pytest.mark.parametrize(["ignore_cfg", "candidate", "result"], [

tests/test_find_extra_reqs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def ignore_reqs(x, y):
8080
def test_main_failure(monkeypatch, caplog, fake_opts):
8181
monkeypatch.setattr(optparse, 'OptionParser', fake_opts)
8282

83-
caplog.setLevel(logging.WARN)
83+
caplog.set_level(logging.WARN)
8484

8585
monkeypatch.setattr(find_extra_reqs, 'find_extra_reqs', lambda x: [
8686
'extra'
@@ -90,9 +90,9 @@ def test_main_failure(monkeypatch, caplog, fake_opts):
9090
find_extra_reqs.main()
9191
assert excinfo.value == 1
9292

93-
assert caplog.records()[0].message == \
93+
assert caplog.records[0].message == \
9494
'Extra requirements:'
95-
assert caplog.records()[1].message == \
95+
assert caplog.records[1].message == \
9696
'extra in requirements.txt'
9797

9898

@@ -145,7 +145,7 @@ def parse_args(self):
145145
(logging.WARN, 'warn')]:
146146
find_extra_reqs.log.log(*event)
147147

148-
messages = [r.message for r in caplog.records()]
148+
messages = [r.message for r in caplog.records]
149149
# first message is always the usage message
150150
if verbose_cfg or debug_cfg:
151151
assert messages[1:] == result

tests/test_find_missing_reqs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_find_missing_reqs(monkeypatch):
7474
def test_main_failure(monkeypatch, caplog, fake_opts):
7575
monkeypatch.setattr(optparse, 'OptionParser', fake_opts)
7676

77-
caplog.setLevel(logging.WARN)
77+
caplog.set_level(logging.WARN)
7878

7979
monkeypatch.setattr(find_missing_reqs, 'find_missing_reqs', lambda x: [
8080
('missing', [common.FoundModule('missing', 'missing.py',
@@ -85,9 +85,9 @@ def test_main_failure(monkeypatch, caplog, fake_opts):
8585
find_missing_reqs.main()
8686
assert excinfo.value == 1
8787

88-
assert caplog.records()[0].message == \
88+
assert caplog.records[0].message == \
8989
'Missing requirements:'
90-
assert caplog.records()[1].message == \
90+
assert caplog.records[1].message == \
9191
'location.py:1 dist=missing module=missing'
9292

9393

@@ -139,7 +139,7 @@ def parse_args(self):
139139
(logging.WARN, 'warn')]:
140140
find_missing_reqs.log.log(*event)
141141

142-
messages = [r.message for r in caplog.records()]
142+
messages = [r.message for r in caplog.records]
143143
# first message is always the usage message
144144
if verbose_cfg or debug_cfg:
145145
assert messages[1:] == result

0 commit comments

Comments
 (0)