diff --git a/CHANGES b/CHANGES index cf43b420f..b75bf8528 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,9 @@ Bugs fixed * #1499: With non-callable `setup` in a conf.py, now sphinx-build emits user-friendly error message. * #1502: In autodoc, fix display of parameter defaults containing backslashes. +* #1226: autodoc, autosummary: importing setup.py by automodule will invoke + setup process and execute `sys.exit()`. Now sphinx avoids SystemExit + exception and emits warnings without unexpected termination. Release 1.2.2 (released Mar 2, 2014) ==================================== diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index b6343171e..423f921a2 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -347,15 +347,19 @@ class Documenter(object): return True # this used to only catch SyntaxError, ImportError and AttributeError, # but importing modules with side effects can raise all kinds of errors - except Exception: + except (Exception, SystemExit) as e: if self.objpath: errmsg = 'autodoc: failed to import %s %r from module %r' % \ (self.objtype, '.'.join(self.objpath), self.modname) else: errmsg = 'autodoc: failed to import %s %r' % \ (self.objtype, self.fullname) - errmsg += '; the following exception was raised:\n%s' % \ - traceback.format_exc() + if isinstance(e, SystemExit): + errmsg += ('; the module executes module level statement ' + + 'and it might call sys.exit().') + else: + errmsg += '; the following exception was raised:\n%s' % \ + traceback.format_exc() dbg(errmsg) self.directive.warn(errmsg) self.env.note_reread() diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 20e7fc916..47ef9868a 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -242,6 +242,9 @@ def find_autosummary_in_docstring(name, module=None, filename=None): pass except ImportError, e: print "Failed to import '%s': %s" % (name, e) + except SystemExit, e: + print("Failed to import '%s'; the module executes module level " + "statement and it might call sys.exit()." % name) return [] def find_autosummary_in_lines(lines, module=None, filename=None):