* Fix: autodoc, autosummary: importing setup.py will invoke setup process and execute sys.exit(). Now sphinx avoids SystemExit exception and emits warnings without unexpected termination. Closes #1226

This commit is contained in:
Takayuki Shimizukawa 2014-07-05 00:11:59 +09:00
parent b3aa4aa81b
commit 4d69072f44
3 changed files with 13 additions and 3 deletions

View File

@ -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)
====================================

View File

@ -347,13 +347,17 @@ 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)
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)

View File

@ -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):