Show More
@@ -57,6 +57,11 b' ipython_execlines:' | |||
|
57 | 57 | conf.py as `None`, then it has the effect of making no imports available. |
|
58 | 58 | If omitted from conf.py altogether, then the default value of |
|
59 | 59 | ['import numpy as np', 'import matplotlib.pyplot as plt'] is used. |
|
60 | ipython_holdcount | |
|
61 | When the @suppress pseudo-decorator is used, the execution count can be | |
|
62 | incremented or not. The default behavior is to hold the execution count, | |
|
63 | corresponding to a value of `True`. Set this to `False` to increment | |
|
64 | the execution count after each suppressed command. | |
|
60 | 65 | |
|
61 | 66 | As an example, to use the IPython directive when `matplotlib` is not available, |
|
62 | 67 | one sets the backend to `None`:: |
@@ -363,7 +368,6 b' class EmbeddedSphinxShell(object):' | |||
|
363 | 368 | # so splitter buffer gets reset |
|
364 | 369 | |
|
365 | 370 | continuation = ' %s:'%''.join(['.']*(len(str(lineno))+2)) |
|
366 | Nc = len(continuation) | |
|
367 | 371 | |
|
368 | 372 | if is_savefig: |
|
369 | 373 | image_file, image_directive = self.process_image(decorator) |
@@ -371,23 +375,29 b' class EmbeddedSphinxShell(object):' | |||
|
371 | 375 | ret = [] |
|
372 | 376 | is_semicolon = False |
|
373 | 377 | |
|
378 | # Hold the execution count, if requested to do so. | |
|
379 | if is_suppress and self.hold_count: | |
|
380 | store_history = False | |
|
381 | else: | |
|
382 | store_history = True | |
|
383 | ||
|
374 | 384 | for i, line in enumerate(input_lines): |
|
375 | 385 | if line.endswith(';'): |
|
376 | 386 | is_semicolon = True |
|
377 | 387 | |
|
378 | if i==0: | |
|
388 | if i == 0: | |
|
379 | 389 | # process the first input line |
|
380 | 390 | if is_verbatim: |
|
381 | 391 | self.process_input_line('') |
|
382 | 392 | self.IP.execution_count += 1 # increment it anyway |
|
383 | 393 | else: |
|
384 | 394 | # only submit the line in non-verbatim mode |
|
385 |
self.process_input_line(line, store_history= |
|
|
395 | self.process_input_line(line, store_history=store_history) | |
|
386 | 396 | formatted_line = '%s %s'%(input_prompt, line) |
|
387 | 397 | else: |
|
388 | 398 | # process a continuation line |
|
389 | 399 | if not is_verbatim: |
|
390 |
self.process_input_line(line, store_history= |
|
|
400 | self.process_input_line(line, store_history=store_history) | |
|
391 | 401 | |
|
392 | 402 | formatted_line = '%s %s'%(continuation, line) |
|
393 | 403 | |
@@ -675,14 +685,15 b' class IPythonDirective(Directive):' | |||
|
675 | 685 | promptout = config.ipython_promptout |
|
676 | 686 | mplbackend = config.ipython_mplbackend |
|
677 | 687 | exec_lines = config.ipython_execlines |
|
688 | hold_count = config.ipython_holdcount | |
|
678 | 689 | |
|
679 | 690 | return (savefig_dir, source_dir, rgxin, rgxout, |
|
680 | promptin, promptout, mplbackend, exec_lines) | |
|
691 | promptin, promptout, mplbackend, exec_lines, hold_count) | |
|
681 | 692 | |
|
682 | 693 | def setup(self): |
|
683 | 694 | # Get configuration values. |
|
684 | (savefig_dir, source_dir, rgxin, rgxout, promptin, | |
|
685 |
|
|
|
695 | (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout, | |
|
696 | mplbackend, exec_lines, hold_count) = self.get_config_options() | |
|
686 | 697 | |
|
687 | 698 | if self.shell is None: |
|
688 | 699 | # We will be here many times. However, when the |
@@ -718,6 +729,7 b' class IPythonDirective(Directive):' | |||
|
718 | 729 | self.shell.promptout = promptout |
|
719 | 730 | self.shell.savefig_dir = savefig_dir |
|
720 | 731 | self.shell.source_dir = source_dir |
|
732 | self.shell.hold_count = hold_count | |
|
721 | 733 | |
|
722 | 734 | # setup bookmark for saving figures directory |
|
723 | 735 | self.shell.process_input_line('bookmark ipy_savedir %s'%savefig_dir, |
@@ -796,16 +808,20 b' def setup(app):' | |||
|
796 | 808 | re.compile('Out\[(\d+)\]:\s?(.*)\s*'), 'env') |
|
797 | 809 | app.add_config_value('ipython_promptin', 'In [%d]:', 'env') |
|
798 | 810 | app.add_config_value('ipython_promptout', 'Out[%d]:', 'env') |
|
811 | ||
|
799 | 812 | # We could just let matplotlib pick whatever is specified as the default |
|
800 | 813 | # backend in the matplotlibrc file, but this would cause issues if the |
|
801 | 814 | # backend didn't work in headless environments. For this reason, 'agg' |
|
802 | 815 | # is a good default backend choice. |
|
803 | 816 | app.add_config_value('ipython_mplbackend', 'agg', 'env') |
|
817 | ||
|
804 | 818 | # If the user sets this config value to `None`, then EmbeddedSphinxShell's |
|
805 | 819 | # __init__ method will treat it as []. |
|
806 | 820 | execlines = ['import numpy as np', 'import matplotlib.pyplot as plt'] |
|
807 | 821 | app.add_config_value('ipython_execlines', execlines, 'env') |
|
808 | 822 | |
|
823 | app.add_config_value('ipython_holdcount', True, 'env') | |
|
824 | ||
|
809 | 825 | # Simple smoke test, needs to be converted to a proper automatic test. |
|
810 | 826 | def test(): |
|
811 | 827 |
General Comments 0
You need to be logged in to leave comments.
Login now