@@ -247,13 +247,15 @@ def block_parser(part, rgxin, rgxout, fmtin, fmtout):
247
247
class EmbeddedSphinxShell (object ):
248
248
"""An embedded IPython instance to run inside Sphinx"""
249
249
250
- def __init__ (self , exec_lines = None ):
250
+ def __init__ (self , exec_lines = None , state = None ):
251
251
252
252
self .cout = StringIO ()
253
253
254
254
if exec_lines is None :
255
255
exec_lines = []
256
256
257
+ self .state = state
258
+
257
259
# Create config object for IPython
258
260
config = Config ()
259
261
config .InteractiveShell .autocall = False
@@ -441,7 +443,17 @@ def process_input(self, data, input_prompt, lineno):
441
443
# output any exceptions raised during execution to stdout
442
444
# unless :okexcept: has been specified.
443
445
if not is_okexcept and "Traceback" in output :
446
+ filename = self .state .document .current_source
447
+ lineno = self .state .document .current_line
448
+ try :
449
+ lineno = int (lineno ) - 1
450
+ except :
451
+ pass
452
+ s = "\n Exception in %s at line %s:\n " % (filename , lineno )
453
+ sys .stdout .write ('\n \n >>>' + '-' * 73 )
454
+ sys .stdout .write (s )
444
455
sys .stdout .write (output )
456
+ sys .stdout .write ('<<<' + '-' * 73 + '\n \n ' )
445
457
446
458
self .cout .truncate (0 )
447
459
return (ret , input_lines , output , is_doctest , decorator , image_file ,
@@ -737,7 +749,7 @@ def setup(self):
737
749
738
750
# Must be called after (potentially) importing matplotlib and
739
751
# setting its backend since exec_lines might import pylab.
740
- self .shell = EmbeddedSphinxShell (exec_lines )
752
+ self .shell = EmbeddedSphinxShell (exec_lines , self . state )
741
753
742
754
# Store IPython directive to enable better error messages
743
755
self .shell .directive = self
0 commit comments