Skip to content
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

PR: Add validation for custom interpreter option #6354

Merged
merged 6 commits into from
Feb 3, 2018
Merged
Show file tree
Hide file tree
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
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