Show More
@@ -127,6 +127,7 b' from __future__ import print_function' | |||||
127 |
|
127 | |||
128 | # Stdlib |
|
128 | # Stdlib | |
129 | import atexit |
|
129 | import atexit | |
|
130 | import errno | |||
130 | import os |
|
131 | import os | |
131 | import re |
|
132 | import re | |
132 | import sys |
|
133 | import sys | |
@@ -365,8 +366,8 b' class EmbeddedSphinxShell(object):' | |||||
365 | source_dir = self.source_dir |
|
366 | source_dir = self.source_dir | |
366 | saveargs = decorator.split(' ') |
|
367 | saveargs = decorator.split(' ') | |
367 | filename = saveargs[1] |
|
368 | filename = saveargs[1] | |
368 | # insert relative path to image file in source |
|
369 | # insert relative path to image file in source (as absolute path for Sphinx) | |
369 | outfile = os.path.relpath(os.path.join(savefig_dir,filename), |
|
370 | outfile = '/' + os.path.relpath(os.path.join(savefig_dir,filename), | |
370 | source_dir) |
|
371 | source_dir) | |
371 |
|
372 | |||
372 | imagerows = ['.. image:: %s'%outfile] |
|
373 | imagerows = ['.. image:: %s'%outfile] | |
@@ -849,14 +850,9 b' class IPythonDirective(Directive):' | |||||
849 | config = self.state.document.settings.env.config |
|
850 | config = self.state.document.settings.env.config | |
850 |
|
851 | |||
851 | # get config variables to set figure output directory |
|
852 | # get config variables to set figure output directory | |
852 | outdir = self.state.document.settings.env.app.outdir |
|
|||
853 | savefig_dir = config.ipython_savefig_dir |
|
853 | savefig_dir = config.ipython_savefig_dir | |
854 |
source_dir = |
|
854 | source_dir = self.state.document.settings.env.srcdir | |
855 | if savefig_dir is None: |
|
855 | savefig_dir = os.path.join(source_dir, savefig_dir) | |
856 | savefig_dir = config.html_static_path or '_static' |
|
|||
857 | if isinstance(savefig_dir, list): |
|
|||
858 | savefig_dir = os.path.join(*savefig_dir) |
|
|||
859 | savefig_dir = os.path.join(outdir, savefig_dir) |
|
|||
860 |
|
856 | |||
861 | # get regex and prompt stuff |
|
857 | # get regex and prompt stuff | |
862 | rgxin = config.ipython_rgxin |
|
858 | rgxin = config.ipython_rgxin | |
@@ -875,6 +871,12 b' class IPythonDirective(Directive):' | |||||
875 | (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout, |
|
871 | (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout, | |
876 | mplbackend, exec_lines, hold_count) = self.get_config_options() |
|
872 | mplbackend, exec_lines, hold_count) = self.get_config_options() | |
877 |
|
873 | |||
|
874 | try: | |||
|
875 | os.makedirs(savefig_dir) | |||
|
876 | except OSError as e: | |||
|
877 | if e.errno != errno.EEXIST: | |||
|
878 | raise | |||
|
879 | ||||
878 | if self.shell is None: |
|
880 | if self.shell is None: | |
879 | # We will be here many times. However, when the |
|
881 | # We will be here many times. However, when the | |
880 | # EmbeddedSphinxShell is created, its interactive shell member |
|
882 | # EmbeddedSphinxShell is created, its interactive shell member | |
@@ -983,7 +985,7 b' def setup(app):' | |||||
983 | setup.app = app |
|
985 | setup.app = app | |
984 |
|
986 | |||
985 | app.add_directive('ipython', IPythonDirective) |
|
987 | app.add_directive('ipython', IPythonDirective) | |
986 |
app.add_config_value('ipython_savefig_dir', |
|
988 | app.add_config_value('ipython_savefig_dir', 'savefig', 'env') | |
987 | app.add_config_value('ipython_rgxin', |
|
989 | app.add_config_value('ipython_rgxin', | |
988 | re.compile('In \[(\d+)\]:\s?(.*)\s*'), 'env') |
|
990 | re.compile('In \[(\d+)\]:\s?(.*)\s*'), 'env') | |
989 | app.add_config_value('ipython_rgxout', |
|
991 | app.add_config_value('ipython_rgxout', |
General Comments 0
You need to be logged in to leave comments.
Login now