Skip to content

Commit

Permalink
Merge pull request #6354 from dalthviz/fixes_issue_4958
Browse files Browse the repository at this point in the history
PR: Add validation for custom interpreter option
  • Loading branch information
ccordoba12 authored Feb 3, 2018
2 parents d85dcbd + 1942109 commit 24d8444
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spyder/utils/ipython/kernelspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from spyder.config.base import get_module_source_path
from spyder.config.main import CONF
from spyder.utils.encoding import to_unicode_from_fs
from spyder.utils.programs import is_python_interpreter
from spyder.py3compat import PY2, iteritems, to_text_string, to_binary_string
from spyder.utils.misc import (add_pathlist_to_PYTHONPATH,
get_python_executable)
Expand Down Expand Up @@ -43,6 +44,11 @@ def argv(self):
# to the kernel sys.path
os.environ.pop('VIRTUAL_ENV', None)
pyexec = CONF.get('main_interpreter', 'executable')
if not is_python_interpreter(pyexec):
pyexec = get_python_executable()
CONF.set('main_interpreter', 'executable', '')
CONF.set('main_interpreter', 'default', True)
CONF.set('main_interpreter', 'custom', False)

# Fixes Issue #3427
if os.name == 'nt':
Expand Down
18 changes: 17 additions & 1 deletion spyder/utils/ipython/tests/test_spyder_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""

import os

import pytest

from spyder.config.main import CONF
Expand All @@ -18,6 +17,23 @@
from spyder.utils.ipython.kernelspec import SpyderKernelSpec


def test_python_interpreter(tmpdir):
"""Test the validation of the python interpreter."""
# Set a non existing python interpreter
interpreter = str(tmpdir.mkdir('interpreter').join('python'))
CONF.set('main_interpreter', 'default', False)
CONF.set('main_interpreter', 'custom', True)
CONF.set('main_interpreter', 'executable', interpreter)

# Create a kernel spec
kernel_spec = SpyderKernelSpec()

# Assert that the python interprerter is the default one
assert interpreter not in kernel_spec.argv
assert CONF.get('main_interpreter', 'default')
assert not CONF.get('main_interpreter', 'custom')


@pytest.mark.skipif(os.name != 'nt' or not PY2,
reason="It only makes sense on Windows and Python 2")
def test_env_vars():
Expand Down

0 comments on commit 24d8444

Please sign in to comment.