Issue #869: Add option `-T` for printing the full traceback on exception.

This commit is contained in:
Jonathan Waltman 2013-01-04 22:24:46 -06:00
parent ab6706e6ed
commit b338af55df
2 changed files with 15 additions and 10 deletions

View File

@ -1,6 +1,9 @@
Release 1.2 (in development) Release 1.2 (in development)
============================ ============================
* #869: sphinx-build now has the option :option:`-T` for printing the full
traceback after an unhandled exception.
* #940: Fix gettext does not extract figure caption. * #940: Fix gettext does not extract figure caption.
* #1067: Improve the ordering of the JavaScript search results: matches in titles * #1067: Improve the ordering of the JavaScript search results: matches in titles

View File

@ -59,6 +59,7 @@ new and changed files
-w <file> -- write warnings (and errors) to given file -w <file> -- write warnings (and errors) to given file
-W -- turn warnings into errors -W -- turn warnings into errors
-P -- run Pdb on exception -P -- run Pdb on exception
-T -- show full traceback on exception
Modi: Modi:
* without -a and without filenames, write new and changed files. * without -a and without filenames, write new and changed files.
* with -a, write all files. * with -a, write all files.
@ -71,7 +72,7 @@ def main(argv):
nocolor() nocolor()
try: try:
opts, args = getopt.getopt(argv[1:], 'ab:t:d:c:CD:A:ng:NEqQWw:P') opts, args = getopt.getopt(argv[1:], 'ab:t:d:c:CD:A:ng:NEqQWw:PT')
allopts = set(opt[0] for opt in opts) allopts = set(opt[0] for opt in opts)
srcdir = confdir = abspath(args[0]) srcdir = confdir = abspath(args[0])
if not path.isdir(srcdir): if not path.isdir(srcdir):
@ -109,6 +110,7 @@ def main(argv):
buildername = None buildername = None
force_all = freshenv = warningiserror = use_pdb = False force_all = freshenv = warningiserror = use_pdb = False
show_traceback = False
status = sys.stdout status = sys.stdout
warning = sys.stderr warning = sys.stderr
error = sys.stderr error = sys.stderr
@ -185,6 +187,8 @@ def main(argv):
warnfile = val warnfile = val
elif opt == '-P': elif opt == '-P':
use_pdb = True use_pdb = True
elif opt == '-T':
show_traceback = True
if warning and warnfile: if warning and warnfile:
warnfp = open(warnfile, 'w') warnfp = open(warnfile, 'w')
@ -197,14 +201,7 @@ def main(argv):
warningiserror, tags) warningiserror, tags)
app.build(force_all, filenames) app.build(force_all, filenames)
return app.statuscode return app.statuscode
except KeyboardInterrupt: except (Exception, KeyboardInterrupt), err:
if use_pdb:
import pdb
print >>error, red('Interrupted while building, starting debugger:')
traceback.print_exc()
pdb.post_mortem(sys.exc_info()[2])
return 1
except Exception, err:
if use_pdb: if use_pdb:
import pdb import pdb
print >>error, red('Exception occurred while building, ' print >>error, red('Exception occurred while building, '
@ -213,7 +210,12 @@ def main(argv):
pdb.post_mortem(sys.exc_info()[2]) pdb.post_mortem(sys.exc_info()[2])
else: else:
print >>error print >>error
if isinstance(err, SystemMessage): if show_traceback:
traceback.print_exc(None, error)
print >>error
if isinstance(err, KeyboardInterrupt):
print >>error, 'interrupted!'
elif isinstance(err, SystemMessage):
print >>error, red('reST markup error:') print >>error, red('reST markup error:')
print >>error, terminal_safe(err.args[0]) print >>error, terminal_safe(err.args[0])
elif isinstance(err, SphinxError): elif isinstance(err, SphinxError):