##// END OF EJS Templates
Restore some functionality of the sphinx directive....
Matthias Bussonnier -
Show More
@@ -201,7 +201,6 b' from traitlets.config import Config'
201 from IPython import InteractiveShell
201 from IPython import InteractiveShell
202 from IPython.core.profiledir import ProfileDir
202 from IPython.core.profiledir import ProfileDir
203
203
204
205 use_matpltolib = False
204 use_matpltolib = False
206 try:
205 try:
207 import matplotlib
206 import matplotlib
@@ -356,7 +355,6 b' class EmbeddedSphinxShell(object):'
356 self.user_ns = self.IP.user_ns
355 self.user_ns = self.IP.user_ns
357 self.user_global_ns = self.IP.user_global_ns
356 self.user_global_ns = self.IP.user_global_ns
358
357
359 self.lines_waiting = []
360 self.input = ''
358 self.input = ''
361 self.output = ''
359 self.output = ''
362 self.tmp_profile_dir = tmp_profile_dir
360 self.tmp_profile_dir = tmp_profile_dir
@@ -387,16 +385,16 b' class EmbeddedSphinxShell(object):'
387 self.cout.seek(0)
385 self.cout.seek(0)
388 self.cout.truncate(0)
386 self.cout.truncate(0)
389
387
390 def process_input_line(self, line, store_history=True):
388 def process_input_line(self, line, store_history):
389 return self.process_input_lines([line], store_history=store_history)
390
391 def process_input_lines(self, lines, store_history=True):
391 """process the input, capturing stdout"""
392 """process the input, capturing stdout"""
392 stdout = sys.stdout
393 stdout = sys.stdout
394 source_raw = '\n'.join(lines)
393 try:
395 try:
394 sys.stdout = self.cout
396 sys.stdout = self.cout
395 self.lines_waiting.append(line)
397 self.IP.run_cell(source_raw, store_history=store_history)
396 source_raw = ''.join(self.lines_waiting)
397 if self.IP.check_complete(source_raw)[0] != 'incomplete':
398 self.lines_waiting = []
399 self.IP.run_cell(source_raw, store_history=store_history)
400 finally:
398 finally:
401 sys.stdout = stdout
399 sys.stdout = stdout
402
400
@@ -470,28 +468,25 b' class EmbeddedSphinxShell(object):'
470
468
471 # Note: catch_warnings is not thread safe
469 # Note: catch_warnings is not thread safe
472 with warnings.catch_warnings(record=True) as ws:
470 with warnings.catch_warnings(record=True) as ws:
473 for i, line in enumerate(input_lines):
471 if input_lines[0].endswith(';'):
474 if line.endswith(';'):
472 is_semicolon = True
475 is_semicolon = True
473 #for i, line in enumerate(input_lines):
474
475 # process the first input line
476 if is_verbatim:
477 self.process_input_lines([''])
478 self.IP.execution_count += 1 # increment it anyway
479 else:
480 # only submit the line in non-verbatim mode
481 self.process_input_lines(input_lines, store_history=store_history)
476
482
483 if not is_suppress:
484 for i, line in enumerate(input_lines):
477 if i == 0:
485 if i == 0:
478 # process the first input line
479 if is_verbatim:
480 self.process_input_line('')
481 self.IP.execution_count += 1 # increment it anyway
482 else:
483 # only submit the line in non-verbatim mode
484 self.process_input_line(line, store_history=store_history)
485 formatted_line = '%s %s'%(input_prompt, line)
486 formatted_line = '%s %s'%(input_prompt, line)
486 else:
487 else:
487 # process a continuation line
488 if not is_verbatim:
489 self.process_input_line(line, store_history=store_history)
490
491 formatted_line = '%s %s'%(continuation, line)
488 formatted_line = '%s %s'%(continuation, line)
492
489 ret.append(formatted_line)
493 if not is_suppress:
494 ret.append(formatted_line)
495
490
496 if not is_suppress and len(rest.strip()) and is_verbatim:
491 if not is_suppress and len(rest.strip()) and is_verbatim:
497 # The "rest" is the standard output of the input. This needs to be
492 # The "rest" is the standard output of the input. This needs to be
@@ -582,7 +577,6 b' class EmbeddedSphinxShell(object):'
582 raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno))
577 raise RuntimeError('Non Expected warning in `{}` line {}'.format(filename, lineno))
583
578
584 self.cout.truncate(0)
579 self.cout.truncate(0)
585
586 return (ret, input_lines, processed_output,
580 return (ret, input_lines, processed_output,
587 is_doctest, decorator, image_file, image_directive)
581 is_doctest, decorator, image_file, image_directive)
588
582
@@ -734,7 +728,6 b' class EmbeddedSphinxShell(object):'
734 # will truncate tracebacks.
728 # will truncate tracebacks.
735 sys.stdout.write(e)
729 sys.stdout.write(e)
736 raise RuntimeError('An invalid block was detected.')
730 raise RuntimeError('An invalid block was detected.')
737
738 out_data = \
731 out_data = \
739 self.process_output(data, output_prompt, input_lines,
732 self.process_output(data, output_prompt, input_lines,
740 output, is_doctest, decorator,
733 output, is_doctest, decorator,
General Comments 0
You need to be logged in to leave comments. Login now