From 3f2b58c0d898d96e9d70b6d3dadafa24fc373da2 Mon Sep 17 00:00:00 2001 From: y-p Date: Sat, 25 Jan 2014 01:12:10 +0200 Subject: [PATCH 1/2] CLN: add clarifying comment to ipython_directive.py --- doc/sphinxext/ipython_directive.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/sphinxext/ipython_directive.py b/doc/sphinxext/ipython_directive.py index e228542b64b4d..c5eea939e3027 100644 --- a/doc/sphinxext/ipython_directive.py +++ b/doc/sphinxext/ipython_directive.py @@ -438,6 +438,8 @@ def process_input(self, data, input_prompt, lineno): elif is_semicolon: # get spacing right ret.append('') + # output any exceptions raised during execution to stdout + # unless :okexcept: has been specified. if not is_okexcept and "Traceback" in output: sys.stdout.write(output) From bd81dd1c348627e435ae91d4c854a997b0b0f3f3 Mon Sep 17 00:00:00 2001 From: y-p Date: Sat, 25 Jan 2014 01:44:25 +0200 Subject: [PATCH 2/2] BLD/DOC: add context info on exception during sphinx run --- doc/sphinxext/ipython_directive.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/sphinxext/ipython_directive.py b/doc/sphinxext/ipython_directive.py index c5eea939e3027..137201ef942b2 100644 --- a/doc/sphinxext/ipython_directive.py +++ b/doc/sphinxext/ipython_directive.py @@ -247,13 +247,15 @@ def block_parser(part, rgxin, rgxout, fmtin, fmtout): class EmbeddedSphinxShell(object): """An embedded IPython instance to run inside Sphinx""" - def __init__(self, exec_lines=None): + def __init__(self, exec_lines=None,state=None): self.cout = StringIO() if exec_lines is None: exec_lines = [] + self.state = state + # Create config object for IPython config = Config() config.InteractiveShell.autocall = False @@ -441,7 +443,17 @@ def process_input(self, data, input_prompt, lineno): # output any exceptions raised during execution to stdout # unless :okexcept: has been specified. if not is_okexcept and "Traceback" in output: + filename = self.state.document.current_source + lineno = self.state.document.current_line + try: + lineno = int(lineno) -1 + except: + pass + s = "\nException in %s at line %s:\n" % (filename, lineno) + sys.stdout.write('\n\n>>>'+'-'*73) + sys.stdout.write(s) sys.stdout.write(output) + sys.stdout.write('<<<' + '-'*73+'\n\n') self.cout.truncate(0) return (ret, input_lines, output, is_doctest, decorator, image_file, @@ -737,7 +749,7 @@ def setup(self): # Must be called after (potentially) importing matplotlib and # setting its backend since exec_lines might import pylab. - self.shell = EmbeddedSphinxShell(exec_lines) + self.shell = EmbeddedSphinxShell(exec_lines, self.state) # Store IPython directive to enable better error messages self.shell.directive = self