Skip to content

Commit

Permalink
Merge pull request #7306 from ccordoba12/move-kernel-out
Browse files Browse the repository at this point in the history
PR: Move all kernel code to an external package called spyder-kernels
  • Loading branch information
ccordoba12 authored Jun 23, 2018
2 parents 707e353 + f1cafb5 commit 3e3e70e
Show file tree
Hide file tree
Showing 45 changed files with 145 additions and 3,944 deletions.
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ install:
- "conda install jupyter_client=5.2.2"
# Fix problems with latest pyqt
- "conda install pyqt=5.6*"
# Install spyder-kernels
- "pip install -q --no-deps spyder-kernels==0.*"

build: false

Expand Down
4 changes: 2 additions & 2 deletions continuous_integration/circle/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh
export PATH="$HOME/miniconda/bin:$PATH"
source activate test

# Install ciocheck (not working right now)
#conda install -q ciocheck -c spyder-ide --no-update-deps
# Install spyder-kernels
pip install -q --no-deps spyder-kernels==0.*
6 changes: 0 additions & 6 deletions continuous_integration/circle/modules_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ for f in spyder/*/*/*.py; do
if [[ $f == spyder/utils/help/*.py ]]; then
continue
fi
if [[ $f == spyder/utils/ipython/start_kernel.py ]]; then
continue
fi
if [[ $f == spyder/utils/ipython/spyder_kernel.py ]]; then
continue
fi
if [[ $f == spyder/utils/site/sitecustomize.py ]]; then
continue
fi
Expand Down
3 changes: 3 additions & 0 deletions continuous_integration/travis/install-qt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ if [ "$USE_CONDA" = "no" ]; then

# Install qtpy from Github
pip install git+https://github.com/spyder-ide/qtpy.git
pip install -q spyder-kernels==0.*
elif [ "$USE_PYQT" = "pyqt5" ]; then
conda install -q qt=5.* pyqt=5.* qtconsole matplotlib
pip install -q --no-deps spyder-kernels==0.*
else
conda install -q qt=4.* pyqt=4.* qtconsole matplotlib
pip install -q --no-deps spyder-kernels==0.*
fi
1 change: 1 addition & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ pyzmq
chardet>=2.0.0
numpydoc
pyqt5
spyder-kernels<1.0
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ def run(self):
'numpydoc',
# Packages for pyqt5 are only available in
# Python 3
'pyqt5<5.10;python_version>="3"'
'pyqt5<5.10;python_version>="3"',
'spyder-kernels<1.0'
]

extras_require = {
Expand Down
1 change: 1 addition & 0 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from spyder import requirements
requirements.check_path()
requirements.check_qt()
requirements.check_spyder_kernels()


#==============================================================================
Expand Down
13 changes: 10 additions & 3 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from spyder import __trouble_url__, __project_url__
from spyder.app import start
from spyder.app.mainwindow import MainWindow # Tests fail without this import
from spyder.config.base import get_home_dir
from spyder.config.base import get_home_dir, get_module_path
from spyder.config.main import CONF
from spyder.plugins import TabFilter
from spyder.plugins.help import ObjectComboBox
Expand Down Expand Up @@ -326,17 +326,22 @@ def test_window_title(main_window, tmpdir):

@pytest.mark.slow
@pytest.mark.single_instance
@pytest.mark.skipif(PY2 and os.environ.get('CI', None) is None,
reason="It's not meant to be run outside of CIs in Python 2")
def test_single_instance_and_edit_magic(main_window, qtbot, tmpdir):
"""Test single instance mode and for %edit magic."""
editorstack = main_window.editor.get_current_editorstack()
shell = main_window.ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)

lock_code = ("from spyder.config.base import get_conf_path\n"
spy_dir = osp.dirname(get_module_path('spyder'))
lock_code = ("import sys\n"
"sys.path.append('{}')\n"
"from spyder.config.base import get_conf_path\n"
"from spyder.utils.external import lockfile\n"
"lock_file = get_conf_path('spyder.lock')\n"
"lock = lockfile.FilesystemLock(lock_file)\n"
"lock_created = lock.lock()")
"lock_created = lock.lock()".format(spy_dir))

# Test single instance
with qtbot.waitSignal(shell.executed):
Expand Down Expand Up @@ -1489,6 +1494,8 @@ def test_tabfilter_typeerror_full(main_window):

@flaky(max_runs=3)
@pytest.mark.slow
@pytest.mark.skipif(os.environ.get('CI', None) is None,
reason="It's not meant to be run outside of CIs")
def test_help_opens_when_show_tutorial_full(main_window, qtbot):
"""Test fix for #6317 : 'Show tutorial' opens the help plugin if closed."""
HELP_STR = "Help"
Expand Down
37 changes: 3 additions & 34 deletions spyder/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,49 +418,18 @@ def translate_gettext(x):
#==============================================================================
# Namespace Browser (Variable Explorer) configuration management
#==============================================================================
def get_supported_types():
"""
Return a dictionnary containing types lists supported by the
namespace browser:
dict(picklable=picklable_types, editable=editables_types)
See:
get_remote_data function in spyder/widgets/variableexplorer/utils/monitor.py
Note:
If you update this list, don't forget to update doc/variablexplorer.rst
"""
from datetime import date, timedelta
editable_types = [int, float, complex, list, dict, tuple, date, timedelta
] + list(TEXT_TYPES) + list(INT_TYPES)
try:
from numpy import ndarray, matrix, generic
editable_types += [ndarray, matrix, generic]
except:
pass
try:
from pandas import DataFrame, Series, DatetimeIndex
editable_types += [DataFrame, Series, DatetimeIndex]
except:
pass
picklable_types = editable_types[:]
try:
from spyder.pil_patch import Image
editable_types.append(Image.Image)
except:
pass
return dict(picklable=picklable_types, editable=editable_types)

# Variable explorer display / check all elements data types for sequences:
# (when saving the variable explorer contents, check_all is True,
# see widgets/variableexplorer/namespacebrowser.py:NamespaceBrowser.save_data)
CHECK_ALL = False #XXX: If True, this should take too much to compute...

EXCLUDED_NAMES = ['nan', 'inf', 'infty', 'little_endian', 'colorbar_doc',
'typecodes', '__builtins__', '__main__', '__doc__', 'NaN',
'Inf', 'Infinity', 'sctypes', 'rcParams', 'rcParamsDefault',
'sctypeNA', 'typeNA', 'False_', 'True_',]

# To be able to get and set variables between Python 2 and 3
PICKLE_PROTOCOL = 2


#==============================================================================
# Mac application utilities
Expand Down
3 changes: 2 additions & 1 deletion spyder/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
import os.path as osp
import sys

from spyder_kernels.utils import iofuncs

from spyder.config.base import _
from spyder.utils import iofuncs


#==============================================================================
Expand Down
3 changes: 2 additions & 1 deletion spyder/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
import pydoc
from code import InteractiveConsole

from spyder_kernels.utils.dochelpers import isdefined

# Local imports:
from spyder.utils.dochelpers import isdefined
from spyder.utils import encoding, programs
from spyder.py3compat import is_text_string
from spyder.utils.misc import remove_backslashes, getcwd_or_home
Expand Down
5 changes: 3 additions & 2 deletions spyder/otherplugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ def _get_spyderplugins(plugin_path, is_io, modnames, modlist):
continue

# Skip names that end in certain suffixes
forbidden_suffixes = ['dist-info', 'egg.info', 'egg-info', 'egg-link']
forbidden_suffixes = ['dist-info', 'egg.info', 'egg-info', 'egg-link',
'kernels']
if any([name.endswith(s) for s in forbidden_suffixes]):
continue

Expand All @@ -87,7 +88,7 @@ def _import_plugin(module_name, plugin_path, modnames, modlist):
module = None

# Then restore the actual loaded module instead of the mock
if module:
if module and getattr(module, 'PLUGIN_CLASS', False):
sys.modules[module_name] = module
modlist.append(module)
modnames.append(module_name)
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class SphinxThread(QThread):
doc : str or dict
A string containing a raw rst text or a dict containing
the doc string components to be rendered.
See spyder.utils.dochelpers.getdoc for description.
See spyder_kernels.utils.dochelpers.getdoc for description.
context : dict
A dict containing the substitution variables for the
layout template
Expand Down
90 changes: 25 additions & 65 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@

# Local imports
from spyder import dependencies
from spyder.config.base import (_, DEV, get_conf_path, get_home_dir,
get_module_path, running_under_pytest)
from spyder.config.base import _, get_conf_path, get_home_dir
from spyder.config.main import CONF
from spyder.plugins import SpyderPluginWidget
from spyder.plugins.configdialog import PluginConfigPage
Expand Down Expand Up @@ -1076,24 +1075,20 @@ def create_new_client(self, give_focus=True, filename='', is_cython=False):
# Else we won't be able to create a client
if not CONF.get('main_interpreter', 'default'):
pyexec = CONF.get('main_interpreter', 'executable')
has_ipykernel = programs.is_module_installed('ipykernel',
interpreter=pyexec)
has_cloudpickle = programs.is_module_installed('cloudpickle',
interpreter=pyexec)
if not (has_ipykernel and has_cloudpickle):
client.show_kernel_error(_("Your Python environment or "
"installation doesn't "
"have the <tt>ipykernel</tt> and "
"<tt>cloudpickle</tt> modules "
"installed on it. Without these modules "
"is not possible for Spyder to create a "
"console for you.<br><br>"
"You can install them by running "
"in a system terminal:<br><br>"
"<tt>pip install ipykernel cloudpickle</tt>"
"<br><br>"
"or<br><br>"
"<tt>conda install ipykernel cloudpickle</tt>"))
has_spyder_kernels = programs.is_module_installed(
'spyder_kernels',
interpreter=pyexec,
version='<1.0.0')
if not has_spyder_kernels:
client.show_kernel_error(
_("Your Python environment or installation doesn't "
"have the <tt>spyder-kernels</tt> module installed "
"on it. Without this module is not possible for "
"Spyder to create a console for you.<br><br>"
"You can install it by running in a system terminal"
":<br><br><tt>conda install spyder-kernels</tt>"
"<br><br>or<br><br>"
"<tt>pip install spyder-kernels</tt>"))
return

self.connect_client_to_kernel(client, is_cython=is_cython)
Expand Down Expand Up @@ -1140,39 +1135,13 @@ def connect_client_to_kernel(self, client, is_cython=False):
shellwidget.kernel_manager = km
shellwidget.kernel_client = kc

def set_editor(self):
"""Set the editor used by the %edit magic"""
# Get Python executable used by Spyder
python = sys.executable
if PY2:
python = encoding.to_unicode_from_fs(python)

# Compose command for %edit
spy_dir = osp.dirname(get_module_path('spyder'))
if DEV:
bootstrap = osp.join(spy_dir, 'bootstrap.py')
if PY2:
bootstrap = encoding.to_unicode_from_fs(bootstrap)
editor = u'"{0}" "{1}" --'.format(python, bootstrap)
else:
import1 = "import sys"
# We need to add spy_dir to sys.path so this test can be
# run in our CIs
if running_under_pytest():
if os.name == 'nt':
import1 = (import1 +
'; sys.path.append(""{}"")'.format(spy_dir))
else:
import1 = (import1 +
"; sys.path.append('{}')".format(spy_dir))
import2 = "from spyder.app.start import send_args_to_spyder"
code = "send_args_to_spyder([sys.argv[-1]])"
editor = u"\"{0}\" -c \"{1}; {2}; {3}\"".format(python,
import1,
import2,
code)

return editor
@Slot(object, object)
def edit_file(self, filename, line):
"""Handle %edit magic petitions."""
if encoding.is_text_file(filename):
# The default line number sent by ipykernel is always the last
# one, but we prefer to use the first.
self.edit_goto.emit(filename, 1, '')

def config_options(self):
"""
Expand Down Expand Up @@ -1232,10 +1201,6 @@ def config_options(self):
spy_cfg.JupyterWidget.style_sheet = style_sheet
spy_cfg.JupyterWidget.syntax_style = color_scheme

# Editor for %edit
if CONF.get('main', 'single_instance'):
spy_cfg.JupyterWidget.editor = self.set_editor()

# Merge QtConsole and Spyder configs. Spyder prefs will have
# prevalence over QtConsole ones
cfg._merge(spy_cfg)
Expand Down Expand Up @@ -1304,6 +1269,9 @@ def register_client(self, client, give_focus=True):
lambda fname, lineno, shellwidget=shellwidget:
self.pdb_has_stopped(fname, lineno, shellwidget))

# To handle %edit magic petitions
shellwidget.custom_edit_requested.connect(self.edit_file)

# Set shell cwd according to preferences
cwd_path = ''
if CONF.get('workingdir', 'console/use_project_or_home_directory'):
Expand Down Expand Up @@ -1548,14 +1516,6 @@ def create_kernel_manager_and_kernel_client(self, connection_file,
"""Create kernel manager and client."""
# Kernel spec
kernel_spec = self.create_kernel_spec(is_cython=is_cython)
if not kernel_spec.env.get('PYTHONPATH'):
error_msg = _("This error is most probably caused by installing "
"Spyder in a directory with non-ascii characters "
"(i.e. characters with tildes, apostrophes or "
"non-latin symbols).<br><br>"
"To fix it, please <b>reinstall</b> Spyder in a "
"different location.")
return (error_msg, None)

# Kernel manager
try:
Expand Down
14 changes: 13 additions & 1 deletion spyder/plugins/variableexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@
# Third party imports
from qtpy.QtCore import QTimer, Signal, Slot
from qtpy.QtWidgets import QGroupBox, QStackedWidget, QVBoxLayout, QWidget
from spyder_kernels.utils.nsview import REMOTE_SETTINGS

# Local imports
from spyder import dependencies
from spyder.config.base import _
from spyder.plugins import SpyderPluginMixin
from spyder.plugins.configdialog import PluginConfigPage
from spyder.utils import icon_manager as ima
from spyder.widgets.variableexplorer.namespacebrowser import NamespaceBrowser
from spyder.widgets.variableexplorer.utils import REMOTE_SETTINGS


PANDAS_REQVER = '>=0.13.1'
dependencies.add('pandas', _("View and edit DataFrames and Series in the "
"Variable Explorer"),
required_version=PANDAS_REQVER, optional=True)

NUMPY_REQVER = '>=1.7'
dependencies.add("numpy", _("View and edit two and three dimensional arrays "
"in the Variable Explorer"),
required_version=NUMPY_REQVER, optional=True)


class VariableExplorerConfigPage(PluginConfigPage):
Expand Down
Loading

0 comments on commit 3e3e70e

Please sign in to comment.