Skip to content

Commit 5d3cc42

Browse files
committed
Perform exe validation with version check in _create_repl
1 parent 5d88865 commit 5d3cc42

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

octave_kernel/kernel.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,21 @@ def _fix_svg_size(self, data):
396396
svg.setAttribute('height', '%dpx' % height)
397397
return svg.toxml()
398398

399+
def _validate_exe_and_get_version(self):
400+
version_cmd = [self.executable, '--version']
401+
version = subprocess.check_output(version_cmd).decode('utf-8')
402+
if not version.startswith('GNU Octave'):
403+
raise OSError('OCTAVE_EXECUTABLE does not point to an octave file, please see README')
404+
return version
405+
399406
def _create_repl(self):
400407
cmd = self.executable
401-
if 'octave' not in cmd:
402-
version_cmd = [self.executable, '--version']
403-
version = subprocess.check_output(version_cmd).decode('utf-8')
404-
if 'version 4' in version:
405-
cmd += ' --no-gui'
408+
409+
# Check for valid octave executable and get its version string
410+
version = self._validate_exe_and_get_version()
411+
if 'version 4' in version:
412+
cmd += ' --no-gui'
413+
406414
# Interactive mode prevents crashing on Windows on syntax errors.
407415
# Delay sourcing the "~/.octaverc" file in case it displays a pager.
408416
cmd += ' --interactive --quiet --no-init-file '
@@ -478,14 +486,13 @@ def _get_executable(self):
478486
fullpath = which(executable)
479487
if 'snap' not in fullpath:
480488
executable = fullpath
481-
if 'octave' not in executable:
482-
raise OSError('OCTAVE_EXECUTABLE does not point to an octave file, please see README')
483489
else:
484490
executable = which('octave-cli')
485491
if not executable:
486492
executable = which('octave')
487493
if not executable:
488494
raise OSError('octave not found, please see README')
495+
489496
return executable.replace(os.path.sep, '/')
490497

491498
def _cleanup(self):

0 commit comments

Comments
 (0)