Skip to content

Commit

Permalink
Merge pull request #204 from blink1073/try-qt-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Jan 4, 2022
2 parents d1491d8 + 741ee6a commit 0ae3405
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/tests.yaml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
# * is a special character in YAML so you have to quote this string
- cron: '0 0 * * 0'

defaults:
run:
shell: bash -l {0}

jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -22,15 +26,18 @@ jobs:
- uses: actions/checkout@v2
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Install Octave
run: |
sudo apt-get update
sudo apt-get install octave
- name: Setup conda ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniforge-variant: Mambaforge
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
conda install -y octave
pip install .[test]
make docker-build
- name: Run test
run: |
make test
xvfb-run --auto-servernum make test
python -m octave_kernel install --user
6 changes: 2 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Prerequisites
-------------
`Jupyter Notebook <http://jupyter.readthedocs.org/en/latest/install.html>`_ and GNU Octave_.

It is recommended to also install ``gnuplot`` for Octave to enable inline plotting.

Installation
------------
To install using pip::
Expand All @@ -24,7 +22,7 @@ To install using conda::
conda install octave_kernel
conda install texinfo # For the inline documentation (shift-tab) to appear.

We require the ``octave-cli`` executable to run the kernel.
We require the ``octave`` executable to run the kernel.
Add that executable's directory to the ``PATH`` environment variable or use the
``OCTAVE_EXECUTABLE`` to point to the executable itself.
Note that on Octave 5 on Windows, the executable is in ``"Octave-5.x.x.x\mingw64\bin"``.
Expand Down Expand Up @@ -77,7 +75,7 @@ init file is explicitly called after the kernel has set ``more off`` to prevent
a lockup when the pager is invoked in ``~/.octaverc``.

The inline toolkit is the ``graphics_toolkit`` used to generate plots for the inline
backend. It defaults to ``gnuplot``. The different backend can be used for inline
backend. It defaults to ``qt``. The different backend can be used for inline
plotting either by using this configuration or by using the plot magic and putting the backend name after ``inline:``, e.g. ``plot -b inline:fltk``.


Expand Down
27 changes: 17 additions & 10 deletions octave_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class OctaveKernel(ProcessMetaKernel):
help_links = HELP_LINKS
kernel_json = Dict(get_kernel_json()).tag(config=True)
cli_options = Unicode('').tag(config=True)
inline_toolkit = Unicode('gnuplot').tag(config=True)
inline_toolkit = Unicode('qt').tag(config=True)

_octave_engine = None
_language_version = None
Expand Down Expand Up @@ -88,6 +88,7 @@ def octave_engine(self):
if self._octave_engine:
return self._octave_engine
self._octave_engine = OctaveEngine(plot_settings=self.plot_settings,
defer_startup=True,
error_handler=self.Error,
stdin_handler=self.raw_input,
stream_handler=self.Print,
Expand All @@ -106,6 +107,8 @@ def do_execute_direct(self, code, silent=False):
self._octave_engine = None
self.do_shutdown(True)
return
if not self.octave_engine._has_startup:
self.octave_engine._startup()
val = ProcessMetaKernel.do_execute_direct(self, code, silent=silent)
if not silent:
try:
Expand Down Expand Up @@ -161,7 +164,7 @@ class OctaveEngine(object):
def __init__(self, error_handler=None, stream_handler=None,
line_handler=None,
stdin_handler=None, plot_settings=None,
inline_toolkit='gnuplot',
inline_toolkit='qt', defer_startup = False,
cli_options='', logger=None):
if not logger:
logger = logging.getLogger(__name__)
Expand All @@ -175,7 +178,10 @@ def __init__(self, error_handler=None, stream_handler=None,
self.stream_handler = stream_handler
self.stdin_handler = stdin_handler or sys.stdin
self.line_handler = line_handler
self._startup(plot_settings)
self._has_startup = False
self._plot_settings = plot_settings
if not defer_startup:
self._startup()
atexit.register(self._cleanup)

@property
Expand Down Expand Up @@ -317,14 +323,15 @@ def extract_figures(self, plot_dir, remove=False):
shutil.rmtree(plot_dir, True)
return images

def _startup(self, plot_settings):
def _startup(self):
self._has_startup = True
cwd = os.getcwd().replace(os.path.sep, '/')
self._default_toolkit = self.eval('graphics_toolkit', silent=True).split()[-1]
cmd = 'more off; source ~/.octaverc; cd("%s");%s'
self.eval(cmd % (cwd, self.repl.prompt_change_cmd), silent=True)
here = os.path.realpath(os.path.dirname(__file__))
self.eval('addpath("%s")' % here.replace(os.path.sep, '/'))
self.plot_settings = plot_settings
self.plot_settings = self._plot_settings

def _handle_svg(self, filename):
"""
Expand Down Expand Up @@ -372,7 +379,7 @@ def _fix_svg_size(self, data):

def _create_repl(self):
cmd = self.executable
if 'octave-cli' not in cmd:
if 'octave' not in cmd:
version_cmd = [self.executable, '--version']
version = subprocess.check_output(version_cmd).decode('utf-8')
if 'version 4' in version:
Expand Down Expand Up @@ -452,12 +459,12 @@ def _get_executable(self):
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')
if 'octave' not in executable:
raise OSError('OCTAVE_EXECUTABLE does not point to an octave file, please see README')
else:
executable = which('octave-cli')
executable = which('octave')
if not executable:
raise OSError('octave-cli not found, please see README')
raise OSError('octave not found, please see README')
return executable.replace(os.path.sep, '/')

def _cleanup(self):
Expand Down

0 comments on commit 0ae3405

Please sign in to comment.