Add basic debugging support for autodoc.

This commit is contained in:
Jonathan Waltman 2013-01-05 08:28:54 -06:00
parent 51fb8b435b
commit 42c90ee178
2 changed files with 26 additions and 8 deletions

View File

@ -317,13 +317,20 @@ class Documenter(object):
Returns True if successful, False if an error occurred. Returns True if successful, False if an error occurred.
""" """
if self.objpath:
self.env.app.debug('autodoc: from %s import %s',
self.modname, '.'.join(self.objpath))
try: try:
self.env.app.debug('autodoc: import %s', self.modname)
__import__(self.modname) __import__(self.modname)
parent = None parent = None
obj = self.module = sys.modules[self.modname] obj = self.module = sys.modules[self.modname]
self.env.app.debug('autodoc: => %r', obj)
for part in self.objpath: for part in self.objpath:
parent = obj parent = obj
self.env.app.debug('autodoc: getattr(_, %r)', part)
obj = self.get_attr(obj, part) obj = self.get_attr(obj, part)
self.env.app.debug('autodoc: => %r', obj)
self.object_name = part self.object_name = part
self.parent = parent self.parent = parent
self.object = obj self.object = obj
@ -331,12 +338,16 @@ class Documenter(object):
# this used to only catch SyntaxError, ImportError and AttributeError, # this used to only catch SyntaxError, ImportError and AttributeError,
# but importing modules with side effects can raise all kinds of errors # but importing modules with side effects can raise all kinds of errors
except Exception, err: except Exception, err:
if self.env.app and not self.env.app.quiet: if self.objpath:
self.env.app.info(traceback.format_exc().rstrip()) errmsg = 'autodoc: failed to import %s %r from module %r' % \
self.directive.warn( (self.objtype, '.'.join(self.objpath), self.modname)
'autodoc can\'t import/find %s %r, it reported error: ' else:
'"%s", please check your spelling and sys.path' % errmsg = 'autodoc: failed to import %s %r' % \
(self.objtype, str(self.fullname), err)) (self.objtype, self.fullname)
errmsg += '; the following exception was raised:\n%s' % \
traceback.format_exc()
self.env.app.debug(errmsg)
self.directive.warn(errmsg)
self.env.note_reread() self.env.note_reread()
return False return False
@ -1294,6 +1305,10 @@ class AutoDirective(Directive):
self.warnings = [] self.warnings = []
self.result = ViewList() self.result = ViewList()
source, lineno = self.reporter.get_source_and_line(self.lineno)
self.env.app.debug('%s:%s: <input>\n%s',
source, lineno, self.block_text)
# find out what documenter to call # find out what documenter to call
objtype = self.name[4:] objtype = self.name[4:]
doc_class = self._registry[objtype] doc_class = self._registry[objtype]
@ -1314,6 +1329,9 @@ class AutoDirective(Directive):
if not self.result: if not self.result:
return self.warnings return self.warnings
if self.env.app.verbosity >= 2:
self.env.app.debug('autodoc: <output>\n%s', '\n'.join(self.result))
# record all filenames as dependencies -- this will at least # record all filenames as dependencies -- this will at least
# partially make automatic invalidation possible # partially make automatic invalidation possible
for fn in self.filename_set: for fn in self.filename_set:

View File

@ -386,10 +386,10 @@ def test_generate():
assert_warns("import for autodocumenting 'foobar'", assert_warns("import for autodocumenting 'foobar'",
'function', 'foobar', more_content=None) 'function', 'foobar', more_content=None)
# importing # importing
assert_warns("import/find module 'test_foobar'", assert_warns("failed to import module 'test_foobar'",
'module', 'test_foobar', more_content=None) 'module', 'test_foobar', more_content=None)
# attributes missing # attributes missing
assert_warns("import/find function 'util.foobar'", assert_warns("failed to import function 'foobar' from module 'util'",
'function', 'util.foobar', more_content=None) 'function', 'util.foobar', more_content=None)
# test auto and given content mixing # test auto and given content mixing