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