@@ -56,7 +56,7 @@ def search_packages_info(query): # pragma: no cover
56
56
class FoundModule :
57
57
def __init__ (self , modname , filename , locations = None ):
58
58
self .modname = modname
59
- self .filename = filename
59
+ self .filename = os . path . realpath ( filename )
60
60
self .locations = locations or [] # filename, lineno
61
61
62
62
def __repr__ (self ):
@@ -154,6 +154,7 @@ def find_imported_modules(options):
154
154
if options .ignore_files (filename ):
155
155
log .info ('ignoring: %s' , os .path .relpath (filename ))
156
156
continue
157
+ log .debug ('scanning: %s' , os .path .relpath (filename ))
157
158
with open (filename ) as f :
158
159
content = f .read ()
159
160
vis .set_location (filename )
@@ -180,8 +181,10 @@ def find_missing_reqs(options):
180
181
installed_files = {}
181
182
all_pkgs = (pkg .project_name for pkg in get_installed_distributions ())
182
183
for package in search_packages_info (all_pkgs ):
184
+ log .debug ('installed package: %s (at %s)' , package ['name' ],
185
+ package ['location' ])
183
186
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 ))
185
188
installed_files [path ] = package ['name' ]
186
189
package_path = is_package_file (path )
187
190
if package_path :
@@ -190,17 +193,25 @@ def find_missing_reqs(options):
190
193
# a package by its directory path later
191
194
installed_files [package_path ] = package ['name' ]
192
195
196
+ # 3. match imported modules against those packages
193
197
used = collections .defaultdict (list )
194
198
for modname , info in used_modules .items ():
195
199
# probably standard library if it's not in the files list
196
200
if info .filename in installed_files :
197
201
used_name = normalize_name (installed_files [info .filename ])
202
+ log .debug ('used module: %s (from package %s)' , modname ,
203
+ installed_files [info .filename ])
198
204
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 )
199
209
200
- # 3 . compare with requirements.txt
210
+ # 4 . compare with requirements.txt
201
211
explicit = set ()
202
212
for requirement in parse_requirements ('requirements.txt' ,
203
213
session = PipSession ()):
214
+ log .debug ('found requirement: %s' , requirement .name )
204
215
explicit .add (normalize_name (requirement .name ))
205
216
206
217
return [(name , used [name ]) for name in used
@@ -222,6 +233,8 @@ def f(candidate, ignore_cfg=ignore_cfg):
222
233
223
234
224
235
def main ():
236
+ from pip_missing_reqs import __version__
237
+
225
238
usage = 'usage: %prog [options] files or directories'
226
239
parser = optparse .OptionParser (usage )
227
240
parser .add_option ("-f" , "--ignore-file" , dest = "ignore_files" ,
@@ -232,13 +245,14 @@ def main():
232
245
help = "used module names (globs are ok) to ignore" )
233
246
parser .add_option ("-v" , "--verbose" , dest = "verbose" ,
234
247
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" )
235
250
parser .add_option ("--version" , dest = "version" ,
236
251
action = "store_true" , default = False , help = "display version information" )
237
252
238
253
(options , args ) = parser .parse_args ()
239
254
240
255
if options .version :
241
- from pip_missing_reqs import __version__
242
256
sys .exit (__version__ )
243
257
244
258
if not args :
@@ -251,7 +265,14 @@ def main():
251
265
options .paths = args
252
266
253
267
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__ )
255
276
256
277
missing = find_missing_reqs (options )
257
278
0 commit comments