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