Skip to content

Commit

Permalink
Merge pull request #216 from blink1073/fix-plot-dir-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Jan 24, 2022
2 parents b73c7fb + 0e9efa3 commit 793fb0f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions oct2py/ipython/octavemagic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#-----------------------------------------------------------------------------

import os
import tempfile
import shutil

import oct2py

Expand Down Expand Up @@ -246,14 +246,21 @@ def octave(self, line, cell=None, local_ns=None):
if args.size is not None:
width, height = [int(s) for s in args.size.split(',')]

plot_dir_obj = tempfile.TemporaryDirectory()
plot_dir = plot_dir_obj.name

# Handle the temporary directory, defaulting to the Oct2Py instance's
# temp dir.
temp_dir = args.temp_dir
if temp_dir is not None and not os.path.isdir(temp_dir):
if temp_dir and not os.path.isdir(temp_dir):
temp_dir = None
temp_dir = temp_dir or self._oct.temp_dir

# Put the plots in the temp directory so we don't have to make another
# temporary directory.
plot_dir = os.path.join(temp_dir, 'plots')
if os.path.exists(plot_dir):
shutil.rmtree(plot_dir)
os.makedirs(plot_dir)

# match current working directory
# Match current working directory.
self._oct.cd(os.getcwd().replace(os.path.sep, '/'))
value = self._oct.eval(code, stream_handler=self._publish,
plot_dir=plot_dir, plot_width=width, plot_height=height,
Expand Down

0 comments on commit 793fb0f

Please sign in to comment.