summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshimizukawa <shimizukawa@gmail.com>2014-07-05 00:11:59 +0900
committershimizukawa <shimizukawa@gmail.com>2014-07-05 00:11:59 +0900
commit9f4116685768a8b9bdd3b6fd7009affe7d471ac0 (patch)
tree0813f9ba0e4a9330c7337af311244456a4193f74
parentaf6b04791e3e36c129e97da2f7c7a1e9f27c1ebe (diff)
downloadsphinx-9f4116685768a8b9bdd3b6fd7009affe7d471ac0.tar.gz
* 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
-rw-r--r--CHANGES3
-rw-r--r--sphinx/ext/autodoc.py10
-rw-r--r--sphinx/ext/autosummary/generate.py3
3 files changed, 13 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index cf43b420..b75bf852 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 b6343171..423f921a 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 20e7fc91..47ef9868 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):