It raised exceptions trying to get _last_caller.__name__ when
_last_caller was None.
Also:
* Add logger to py2depgraph
* Disable (for now) ModuleFinder's internal debugging.
"""Extract a tree of module imports from a Python script.
"""
"""Extract a tree of module imports from a Python script.
"""
+LOG = logging.getLogger('py2depgraph')
+LOG.setLevel(logging.DEBUG)
+_STREAM_HANDLER = logging.StreamHandler()
+_STREAM_HANDLER.setLevel(logging.CRITICAL)
+_STREAM_HANDLER.setFormatter(
+ logging.Formatter('%(levelname)s - %(message)s'))
+LOG.addHandler(_STREAM_HANDLER)
+
+
class mymf(modulefinder.ModuleFinder):
def __init__(self,*args,**kwargs):
self._depgraph = {}
class mymf(modulefinder.ModuleFinder):
def __init__(self,*args,**kwargs):
self._depgraph = {}
return modulefinder.ModuleFinder.import_hook(self,name,caller,fromlist, level)
finally:
self._last_caller = old_last_caller
return modulefinder.ModuleFinder.import_hook(self,name,caller,fromlist, level)
finally:
self._last_caller = old_last_caller
+ LOG.debug('after import_hook(%s, %s, %s, %s), last_caller is %s'
+ % (name, caller, fromlist, level, self._last_caller))
def import_module(self,partnam,fqname,parent):
r = modulefinder.ModuleFinder.import_module(self,partnam,fqname,parent)
def import_module(self,partnam,fqname,parent):
r = modulefinder.ModuleFinder.import_module(self,partnam,fqname,parent)
+ if None not in [r, self._last_caller]:
self._depgraph.setdefault(self._last_caller.__name__,{})[r.__name__] = 1
return r
self._depgraph.setdefault(self._last_caller.__name__,{})[r.__name__] = 1
return r
options,args = p.parse_args()
options,args = p.parse_args()
+ log_level = logging.CRITICAL - 10*options.verbose
+ _STREAM_HANDLER.setLevel(log_level)
+
- mf = mymf(path=sys.path[:], debug=options.verbose, excludes=[])
+ debug = options.verbose
+ debug = 0
+ mf = mymf(path=sys.path[:], debug=debug, excludes=[])
mf.run_script(script)
pprint({'depgraph':mf._depgraph,'types':mf._types,'paths':mf._paths})
mf.run_script(script)
pprint({'depgraph':mf._depgraph,'types':mf._types,'paths':mf._paths})