##// END OF EJS Templates
Backport PR #10186: Put savefig images back in source directory...
Thomas Kluyver -
Show More
@@ -127,6 +127,7 b' from __future__ import print_function'
127 127
128 128 # Stdlib
129 129 import atexit
130 import errno
130 131 import os
131 132 import re
132 133 import sys
@@ -365,9 +366,9 b' class EmbeddedSphinxShell(object):'
365 366 source_dir = self.source_dir
366 367 saveargs = decorator.split(' ')
367 368 filename = saveargs[1]
368 # insert relative path to image file in source
369 outfile = os.path.relpath(os.path.join(savefig_dir,filename),
370 source_dir)
369 # insert relative path to image file in source (as absolute path for Sphinx)
370 outfile = '/' + os.path.relpath(os.path.join(savefig_dir,filename),
371 source_dir)
371 372
372 373 imagerows = ['.. image:: %s'%outfile]
373 374
@@ -849,14 +850,9 b' class IPythonDirective(Directive):'
849 850 config = self.state.document.settings.env.config
850 851
851 852 # get config variables to set figure output directory
852 outdir = self.state.document.settings.env.app.outdir
853 853 savefig_dir = config.ipython_savefig_dir
854 source_dir = os.path.dirname(self.state.document.current_source)
855 if savefig_dir is None:
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)
854 source_dir = self.state.document.settings.env.srcdir
855 savefig_dir = os.path.join(source_dir, savefig_dir)
860 856
861 857 # get regex and prompt stuff
862 858 rgxin = config.ipython_rgxin
@@ -875,6 +871,12 b' class IPythonDirective(Directive):'
875 871 (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout,
876 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 880 if self.shell is None:
879 881 # We will be here many times. However, when the
880 882 # EmbeddedSphinxShell is created, its interactive shell member
@@ -983,7 +985,7 b' def setup(app):'
983 985 setup.app = app
984 986
985 987 app.add_directive('ipython', IPythonDirective)
986 app.add_config_value('ipython_savefig_dir', None, 'env')
988 app.add_config_value('ipython_savefig_dir', 'savefig', 'env')
987 989 app.add_config_value('ipython_rgxin',
988 990 re.compile('In \[(\d+)\]:\s?(.*)\s*'), 'env')
989 991 app.add_config_value('ipython_rgxout',
General Comments 0
You need to be logged in to leave comments. Login now