From c50054c8dab65814c18c38b3f6ef60fc2e2d007f Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 7 Jan 2011 10:19:45 +0100 Subject: [PATCH] If an autodoc object cannot be imported, always re-read the document and show the full traceback of the import error. --- CHANGES | 6 ++++++ sphinx/environment.py | 12 +++++++++++- sphinx/ext/autodoc.py | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f914c5a00..e8d6620ad 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,12 @@ Release 1.0.7 (in development) ============================== +* If an autodoc object cannot be imported, always re-read the + document containing the directive on next build. + +* If an autodoc object cannot be imported, show the full traceback + of the import error. + * Fix a bug where the removal of download files and images wasn't noticed. diff --git a/sphinx/environment.py b/sphinx/environment.py index cbaee9b26..b5ada1ea6 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -64,7 +64,7 @@ default_settings = { # This is increased every time an environment attribute is added # or changed to properly invalidate pickle files. -ENV_VERSION = 38 +ENV_VERSION = 39 default_substitutions = set([ @@ -295,6 +295,8 @@ class BuildEnvironment: # contains all built docnames self.dependencies = {} # docname -> set of dependent file # names, relative to documentation root + self.reread_always = set() # docnames to re-read unconditionally on + # next build # File metadata self.metadata = {} # docname -> dict of metadata items @@ -344,6 +346,7 @@ class BuildEnvironment: """Remove all traces of a source file in the inventory.""" if docname in self.all_docs: self.all_docs.pop(docname, None) + self.reread_always.discard(docname) self.metadata.pop(docname, None) self.dependencies.pop(docname, None) self.titles.pop(docname, None) @@ -426,6 +429,10 @@ class BuildEnvironment: '.doctree')): changed.add(docname) continue + # check the "reread always" list + if docname in self.reread_always: + changed.add(docname) + continue # check the mtime of the document mtime = self.all_docs[docname] newmtime = path.getmtime(self.doc2path(docname)) @@ -729,6 +736,9 @@ class BuildEnvironment: def note_dependency(self, filename): self.dependencies.setdefault(self.docname, set()).add(filename) + def note_reread(self): + self.reread_always.add(self.docname) + def note_versionchange(self, type, version, node, lineno): self.versionchanges.setdefault(version, []).append( (type, self.temp_data['docname'], lineno, diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 63c263361..b135d3578 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -14,6 +14,7 @@ import re import sys import inspect +import traceback from types import FunctionType, BuiltinFunctionType, MethodType, ClassType from docutils import nodes @@ -336,10 +337,13 @@ class Documenter(object): # this used to only catch SyntaxError, ImportError and AttributeError, # but importing modules with side effects can raise all kinds of errors except Exception, err: + if self.env.app and not self.env.app.quiet: + self.env.app.info(traceback.format_exc().rstrip()) self.directive.warn( 'autodoc can\'t import/find %s %r, it reported error: ' '"%s", please check your spelling and sys.path' % (self.objtype, str(self.fullname), err)) + self.env.note_reread() return False def get_real_modname(self):