Skip to content

Commit

Permalink
Merge pull request #175 from PhilFreeman/snapPlotFix
Browse files Browse the repository at this point in the history
Snap plot fix
  • Loading branch information
Steven Silvester authored May 23, 2020
2 parents 6942177 + e7d82f3 commit 9d4743f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
33 changes: 32 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Configuration
The kernel can be configured by adding an ``octave_kernel_config.py`` file to the
``jupyter`` config path. The ``OctaveKernel`` class offers ``plot_settings``, ``inline_toolkit``,
``kernel_json``, and ``cli_options`` as configurable traits. The available plot settings are:
'format', 'backend', 'width', 'height', and 'resolution'.
'format', 'backend', 'width', 'height', 'resolution', and 'plot_dir'.

.. code:: bash
Expand Down Expand Up @@ -119,6 +119,37 @@ An error that starts with ``gnuplot> set terminal aqua enhanced title`` can be f
adding ``setenv("GNUTERM","qt");`` to ``~/.octaverc`` on MacOS or by installing
``gunplot-x11`` and using ``setenv("GNUTERM", "X11")``.

Octave-Snap (Linux)
~~~~~~~~~~~~~~~~~~~
You can check if you are using a snap version on Linux by checking the path to your Octave
installation.

.. code:: shell
which octave
If the returned path has ``snap`` in it, then Octave is running in a container and you will need to configure the kernel appropriately.

1) Set the environment variable ``OCTAVE_EXECUTABLE="octave"``

.. code:: shell
echo export OCTAVE_EXECUTABLE=\"octave\" >> ~/.bashrc
2) Make a directory for the temporary plot directories that the kernel uses. This *cannot* be a hidden directory.

.. code:: shell
mkdir ~/octavePlots
3) Set ``plot_dir`` to point to your plot directory in ``octave_kernel_config.py``.

.. code:: shell
c.OctaveKernel.plot_settings = dict(plot_dir='<home>/octavePlots')
where ``<home>`` is the absolute path to your home directory. Do not use ``~`` as this resolves to a different location for Octave-Snap.


Blank Plot
~~~~~~~~~~
Expand Down
13 changes: 8 additions & 5 deletions octave_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def plot_settings(self, settings):

# Remove "None" keys so we can use setdefault below.
keys = ['format', 'backend', 'width', 'height', 'resolution',
'backend', 'name']
'backend', 'name', 'plot_dir']
for key in keys:
if key in settings and settings.get(key, None) is None:
del settings[key]
Expand All @@ -200,6 +200,7 @@ def plot_settings(self, settings):
settings.setdefault('height', -1)
settings.setdefault('resolution', 0)
settings.setdefault('name', 'Figure')
settings.setdefault('plot_dir', None)

cmds = []
if settings['backend'] == 'inline':
Expand Down Expand Up @@ -268,7 +269,7 @@ def make_figures(self, plot_dir=None):
wid = settings['width']
hgt = settings['height']
name = settings['name']
plot_dir = plot_dir or tempfile.mkdtemp()
plot_dir = plot_dir or tempfile.mkdtemp(dir=settings['plot_dir'])
plot_dir = plot_dir.replace(os.path.sep, '/')

# Do not overwrite any existing plot files.
Expand Down Expand Up @@ -448,9 +449,11 @@ def _get_executable(self):
# Attempt to get the octave executable
executable = os.environ.get('OCTAVE_EXECUTABLE', None)
if executable:
executable = which(executable)
if 'octave-cli' not in executable:
raise OSError('OCTAVE_EXECUTABLE does not point to an octave-cli file, please see README')
fullpath = which(executable)
if 'snap' not in fullpath:
executable = fullpath
if 'octave-cli' not in executable:
raise OSError('OCTAVE_EXECUTABLE does not point to an octave-cli file, please see README')
else:
executable = which('octave-cli')
if not executable:
Expand Down

0 comments on commit 9d4743f

Please sign in to comment.