Skip to content

Commit 2cbfda8

Browse files
committed
fixes for debian/ubuntu
1 parent 7fe16c5 commit 2cbfda8

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

CHANGELOG.rst

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

5+
1.1.9
6+
7+
- test fixes and cleanup
8+
- remove hard-coded simplejson debugging behaviour
9+
10+
1.1.8
11+
12+
- use os.path.realpath to avoid symlink craziness on debian/ubuntu
13+
14+
1.1.7
15+
16+
- tweak to debug output
17+
18+
1.1.6
19+
20+
- add debug (very verbose) run output
21+
522
1.1.5
623

724
- add header to output to make it clearer when in a larger test run

pip_missing_reqs/__init__.py

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

pip_missing_reqs/find_missing_reqs.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def search_packages_info(query): # pragma: no cover
5656
class FoundModule:
5757
def __init__(self, modname, filename, locations=None):
5858
self.modname = modname
59-
self.filename = filename
59+
self.filename = os.path.realpath(filename)
6060
self.locations = locations or [] # filename, lineno
6161

6262
def __repr__(self):
@@ -154,6 +154,7 @@ def find_imported_modules(options):
154154
if options.ignore_files(filename):
155155
log.info('ignoring: %s', os.path.relpath(filename))
156156
continue
157+
log.debug('scanning: %s', os.path.relpath(filename))
157158
with open(filename) as f:
158159
content = f.read()
159160
vis.set_location(filename)
@@ -180,8 +181,10 @@ def find_missing_reqs(options):
180181
installed_files = {}
181182
all_pkgs = (pkg.project_name for pkg in get_installed_distributions())
182183
for package in search_packages_info(all_pkgs):
184+
log.debug('installed package: %s (at %s)', package['name'],
185+
package['location'])
183186
for file in package['files'] or []:
184-
path = os.path.normpath(os.path.join(package['location'], file))
187+
path = os.path.realpath(os.path.join(package['location'], file))
185188
installed_files[path] = package['name']
186189
package_path = is_package_file(path)
187190
if package_path:
@@ -190,17 +193,25 @@ def find_missing_reqs(options):
190193
# a package by its directory path later
191194
installed_files[package_path] = package['name']
192195

196+
# 3. match imported modules against those packages
193197
used = collections.defaultdict(list)
194198
for modname, info in used_modules.items():
195199
# probably standard library if it's not in the files list
196200
if info.filename in installed_files:
197201
used_name = normalize_name(installed_files[info.filename])
202+
log.debug('used module: %s (from package %s)', modname,
203+
installed_files[info.filename])
198204
used[used_name].append(info)
205+
else:
206+
log.debug(
207+
'used module: %s (from file %s, assuming stdlib or local)',
208+
modname, info.filename)
199209

200-
# 3. compare with requirements.txt
210+
# 4. compare with requirements.txt
201211
explicit = set()
202212
for requirement in parse_requirements('requirements.txt',
203213
session=PipSession()):
214+
log.debug('found requirement: %s', requirement.name)
204215
explicit.add(normalize_name(requirement.name))
205216

206217
return [(name, used[name]) for name in used
@@ -222,6 +233,8 @@ def f(candidate, ignore_cfg=ignore_cfg):
222233

223234

224235
def main():
236+
from pip_missing_reqs import __version__
237+
225238
usage = 'usage: %prog [options] files or directories'
226239
parser = optparse.OptionParser(usage)
227240
parser.add_option("-f", "--ignore-file", dest="ignore_files",
@@ -232,13 +245,14 @@ def main():
232245
help="used module names (globs are ok) to ignore")
233246
parser.add_option("-v", "--verbose", dest="verbose",
234247
action="store_true", default=False, help="be more verbose")
248+
parser.add_option("-d", "--debug", dest="debug",
249+
action="store_true", default=False, help="be *really* verbose")
235250
parser.add_option("--version", dest="version",
236251
action="store_true", default=False, help="display version information")
237252

238253
(options, args) = parser.parse_args()
239254

240255
if options.version:
241-
from pip_missing_reqs import __version__
242256
sys.exit(__version__)
243257

244258
if not args:
@@ -251,7 +265,14 @@ def main():
251265
options.paths = args
252266

253267
logging.basicConfig(format='%(message)s')
254-
log.setLevel(logging.INFO if options.verbose else logging.WARN)
268+
if options.debug:
269+
log.setLevel(logging.DEBUG)
270+
elif options.verbose:
271+
log.setLevel(logging.INFO)
272+
else:
273+
log.setLevel(logging.WARN)
274+
275+
log.info('using pip_missing_reqs-%s from %s', __version__, __file__)
255276

256277
missing = find_missing_reqs(options)
257278

pip_missing_reqs/test_find_missing_reqs.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def fake_opts():
2020
class FakeOptParse:
2121
class options:
2222
paths = ['dummy']
23-
verbose = True
23+
verbose = False
24+
debug = False
2425
version = False
2526
ignore_files = []
2627
ignore_mods = []
@@ -56,7 +57,7 @@ def test_is_package_file(path, result):
5657
def test_FoundModule():
5758
fm = find_missing_reqs.FoundModule('spam', 'ham')
5859
assert fm.modname == 'spam'
59-
assert fm.filename == 'ham'
60+
assert fm.filename == os.path.realpath('ham')
6061
assert fm.locations == []
6162
assert str(fm) == 'FoundModule("spam")'
6263

@@ -257,14 +258,17 @@ def test_ignorer(monkeypatch, ignore_cfg, candidate, result):
257258
assert ignorer(candidate) == result
258259

259260

260-
@pytest.mark.parametrize(["verbose_cfg", "events", "result"], [
261-
(False, [(logging.INFO, 'info'), (logging.WARN, 'warn')], ['warn']),
262-
(True, [(logging.INFO, 'info'), (logging.WARN, 'warn')], ['info', 'warn']),
261+
@pytest.mark.parametrize(["verbose_cfg", "debug_cfg", "result"], [
262+
(False, False, ['warn']),
263+
(True, False, ['info', 'warn']),
264+
(False, True, ['debug', 'info', 'warn']),
265+
(True, True, ['debug', 'info', 'warn']),
263266
])
264-
def test_logging_config(monkeypatch, caplog, verbose_cfg, events, result):
267+
def test_logging_config(monkeypatch, caplog, verbose_cfg, debug_cfg, result):
265268
class options:
266269
paths = ['dummy']
267270
verbose = verbose_cfg
271+
debug = debug_cfg
268272
version = False
269273
ignore_files = []
270274
ignore_mods = []
@@ -285,11 +289,16 @@ def parse_args(self):
285289
monkeypatch.setattr(find_missing_reqs, 'find_missing_reqs', lambda x: [])
286290
find_missing_reqs.main()
287291

288-
for event in events:
292+
for event in [(logging.DEBUG, 'debug'), (logging.INFO, 'info'),
293+
(logging.WARN, 'warn')]:
289294
find_missing_reqs.log.log(*event)
290295

291296
messages = [r.message for r in caplog.records()]
292-
assert messages == result
297+
# first message is always the usage message
298+
if verbose_cfg or debug_cfg:
299+
assert messages[1:] == result
300+
else:
301+
assert messages == result
293302

294303

295304
def test_main_version(monkeypatch, caplog, fake_opts):

0 commit comments

Comments
 (0)