Show More
@@ -44,6 +44,11 ipython_mplbackend: | |||
|
44 | 44 | to '' or 'None', then `matplotlib` will not be automatically imported. If |
|
45 | 45 | not `None`, then the value should specify a backend that is passed to |
|
46 | 46 | `matplotlib.use()`. The default value is 'agg'. |
|
47 | ipython_execlines: | |
|
48 | A list of strings to be exec'd for each embedded Sphinx shell. Typical | |
|
49 | usage is to make certain packages always available. If None, then | |
|
50 | `['import numpy as np', 'from pylab import *']` is used. Set this to an | |
|
51 | empty list if you wish to have no imports always available. | |
|
47 | 52 | |
|
48 | 53 | As an example, to use the IPython directive when `matplotlib` is not available, |
|
49 | 54 | one sets the backend to `None`:: |
@@ -208,17 +213,17 def block_parser(part, rgxin, rgxout, fmtin, fmtout): | |||
|
208 | 213 | class EmbeddedSphinxShell(object): |
|
209 | 214 | """An embedded IPython instance to run inside Sphinx""" |
|
210 | 215 | |
|
211 | def __init__(self): | |
|
216 | def __init__(self, exec_lines=None): | |
|
212 | 217 | |
|
213 | 218 | self.cout = StringIO() |
|
214 | 219 | |
|
220 | if exec_lines is None: | |
|
221 | exec_lines = ['import numpy as np', 'from pylab import *'] | |
|
215 | 222 | |
|
216 | 223 | # Create config object for IPython |
|
217 | 224 | config = Config() |
|
218 | 225 | config.Global.display_banner = False |
|
219 |
config.Global.exec_lines = |
|
|
220 | 'from pylab import *' | |
|
221 | ] | |
|
226 | config.Global.exec_lines = exec_lines | |
|
222 | 227 | config.InteractiveShell.autocall = False |
|
223 | 228 | config.InteractiveShell.autoindent = False |
|
224 | 229 | config.InteractiveShell.colors = 'NoColor' |
@@ -578,17 +583,18 class IPythonDirective(Directive): | |||
|
578 | 583 | promptin = config.ipython_promptin |
|
579 | 584 | promptout = config.ipython_promptout |
|
580 | 585 | mplbackend = config.ipython_mplbackend |
|
586 | exec_lines = config.ipython_execlines | |
|
581 | 587 | |
|
582 | 588 | return (savefig_dir, source_dir, rgxin, rgxout, |
|
583 | promptin, promptout, mplbackend) | |
|
589 | promptin, promptout, mplbackend, exec_lines) | |
|
584 | 590 | |
|
585 | 591 | def setup(self): |
|
586 | 592 | # Get configuration values. |
|
587 | (savefig_dir, source_dir, rgxin, rgxout, | |
|
588 |
|
|
|
593 | (savefig_dir, source_dir, rgxin, rgxout, promptin, | |
|
594 | promptout, mplbackend, exec_lines) = self.get_config_options() | |
|
589 | 595 | |
|
590 | 596 | if self.shell is None: |
|
591 | self.shell = EmbeddedSphinxShell() | |
|
597 | self.shell = EmbeddedSphinxShell(exec_lines) | |
|
592 | 598 | if mplbackend: |
|
593 | 599 | # Each ipython code-block is run in a separate process. |
|
594 | 600 | import matplotlib |
@@ -687,7 +693,7 def setup(app): | |||
|
687 | 693 | app.add_config_value('ipython_promptin', 'In [%d]:', 'env') |
|
688 | 694 | app.add_config_value('ipython_promptout', 'Out[%d]:', 'env') |
|
689 | 695 | app.add_config_value('ipython_mplbackend', 'agg', 'env') |
|
690 | ||
|
696 | app.add_config_value('ipython_execlines', None, 'env') | |
|
691 | 697 | |
|
692 | 698 | # Simple smoke test, needs to be converted to a proper automatic test. |
|
693 | 699 | def test(): |
General Comments 0
You need to be logged in to leave comments.
Login now