Skip to content

Perform the executable validation along with the version check in _create_repl() #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions octave_kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,23 @@ def _fix_svg_size(self, data):
svg.setAttribute('height', '%dpx' % height)
return svg.toxml()

def _validate_exe_and_get_version(self):
version_cmd = [self.executable, '--version']
try:
version = subprocess.check_output(version_cmd).decode('utf-8')
assert version.startswith('GNU Octave')
except (subprocess.CalledProcessError, AssertionError):
raise OSError('OCTAVE_EXECUTABLE does not point to an octave file, please see README')
return version

def _create_repl(self):
cmd = self.executable
if 'octave' not in cmd:
version_cmd = [self.executable, '--version']
version = subprocess.check_output(version_cmd).decode('utf-8')
if 'version 4' in version:
cmd += ' --no-gui'

# Check for valid octave executable and get its version string
version = self._validate_exe_and_get_version()
if 'version 4' in version:
cmd += ' --no-gui'

# Interactive mode prevents crashing on Windows on syntax errors.
# Delay sourcing the "~/.octaverc" file in case it displays a pager.
cmd += ' --interactive --quiet --no-init-file '
Expand Down Expand Up @@ -478,8 +488,6 @@ def _get_executable(self):
fullpath = which(executable)
if 'snap' not in fullpath:
executable = fullpath
if 'octave' not in executable:
raise OSError('OCTAVE_EXECUTABLE does not point to an octave file, please see README')
else:
executable = which('octave-cli')
if not executable:
Expand Down