##// END OF EJS Templates
Put savefig images back in source directory...
Thomas Kluyver -
Show More
@@ -126,6 +126,7 b' Authors'
126
126
127 # Stdlib
127 # Stdlib
128 import atexit
128 import atexit
129 import errno
129 import os
130 import os
130 import re
131 import re
131 import sys
132 import sys
@@ -358,8 +359,8 b' class EmbeddedSphinxShell(object):'
358 source_dir = self.source_dir
359 source_dir = self.source_dir
359 saveargs = decorator.split(' ')
360 saveargs = decorator.split(' ')
360 filename = saveargs[1]
361 filename = saveargs[1]
361 # insert relative path to image file in source
362 # insert relative path to image file in source (as absolute path for Sphinx)
362 outfile = os.path.relpath(os.path.join(savefig_dir,filename),
363 outfile = '/' + os.path.relpath(os.path.join(savefig_dir,filename),
363 source_dir)
364 source_dir)
364
365
365 imagerows = ['.. image:: %s'%outfile]
366 imagerows = ['.. image:: %s'%outfile]
@@ -842,14 +843,9 b' class IPythonDirective(Directive):'
842 config = self.state.document.settings.env.config
843 config = self.state.document.settings.env.config
843
844
844 # get config variables to set figure output directory
845 # get config variables to set figure output directory
845 outdir = self.state.document.settings.env.app.outdir
846 savefig_dir = config.ipython_savefig_dir
846 savefig_dir = config.ipython_savefig_dir
847 source_dir = os.path.dirname(self.state.document.current_source)
847 source_dir = self.state.document.settings.env.srcdir
848 if savefig_dir is None:
848 savefig_dir = os.path.join(source_dir, savefig_dir)
849 savefig_dir = config.html_static_path or '_static'
850 if isinstance(savefig_dir, list):
851 savefig_dir = os.path.join(*savefig_dir)
852 savefig_dir = os.path.join(outdir, savefig_dir)
853
849
854 # get regex and prompt stuff
850 # get regex and prompt stuff
855 rgxin = config.ipython_rgxin
851 rgxin = config.ipython_rgxin
@@ -868,6 +864,12 b' class IPythonDirective(Directive):'
868 (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout,
864 (savefig_dir, source_dir, rgxin, rgxout, promptin, promptout,
869 mplbackend, exec_lines, hold_count) = self.get_config_options()
865 mplbackend, exec_lines, hold_count) = self.get_config_options()
870
866
867 try:
868 os.makedirs(savefig_dir)
869 except OSError as e:
870 if e.errno != errno.EEXIST:
871 raise
872
871 if self.shell is None:
873 if self.shell is None:
872 # We will be here many times. However, when the
874 # We will be here many times. However, when the
873 # EmbeddedSphinxShell is created, its interactive shell member
875 # EmbeddedSphinxShell is created, its interactive shell member
@@ -976,7 +978,7 b' def setup(app):'
976 setup.app = app
978 setup.app = app
977
979
978 app.add_directive('ipython', IPythonDirective)
980 app.add_directive('ipython', IPythonDirective)
979 app.add_config_value('ipython_savefig_dir', None, 'env')
981 app.add_config_value('ipython_savefig_dir', 'savefig', 'env')
980 app.add_config_value('ipython_rgxin',
982 app.add_config_value('ipython_rgxin',
981 re.compile('In \[(\d+)\]:\s?(.*)\s*'), 'env')
983 re.compile('In \[(\d+)\]:\s?(.*)\s*'), 'env')
982 app.add_config_value('ipython_rgxout',
984 app.add_config_value('ipython_rgxout',
General Comments 0
You need to be logged in to leave comments. Login now