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

Utilize Jupyter for instantiating a kernel connection in IPython >= 4 #152

Open
wants to merge 5 commits into
base: master
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
43 changes: 29 additions & 14 deletions ftplugin/python/vim_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def new_ipy(s=''):
new_ipy()

"""
from IPython.kernel import KernelManager
try:
from jupyter_client.manager import KernelManager
except ImportError:
from IPython.kernel import KernelManager
km = KernelManager()
km.start_kernel()
return km_from_string(km.connection_file)
Expand All @@ -107,21 +110,28 @@ def km_from_string(s=''):
import IPython
except ImportError:
raise ImportError("Could not find IPython. " + _install_instructions)
from IPython.config.loader import KeyValueConfigLoader
try:
from IPython.kernel import (
KernelManager,
find_connection_file,
)
from traitlets.config.loader import KeyValueConfigLoader
except ImportError:
from IPython.config.loader import KeyValueConfigLoader
try:
from jupyter_client.manager import KernelManager
from jupyter_client.connect import find_connection_file
except ImportError:
# IPython < 1.0
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
from IPython.zmq.kernelapp import kernel_aliases
try:
from IPython.lib.kernel import find_connection_file
from IPython.kernel import (
KernelManager,
find_connection_file,
)
except ImportError:
# < 0.12, no find_connection_file
pass
# IPython < 1.0
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
from IPython.zmq.kernelapp import kernel_aliases
try:
from IPython.lib.kernel import find_connection_file
except ImportError:
# < 0.12, no find_connection_file
pass

global km, kc, send

Expand All @@ -147,8 +157,13 @@ def km_from_string(s=''):
echo(":IPython " + s + " failed", "Info")
echo("^-- failed '" + s + "' not found", "Error")
return
km = KernelManager(connection_file = fullpath)
km.load_connection_file()
if IPython.version_info[0] >= 4:
km = KernelManager()
km.connection_file = find_connection_file()
km.load_connection_file()
else:
km = KernelManager(connection_file = fullpath)
km.load_connection_file()
else:
if s == '':
echo(":IPython 0.11 requires the full connection string")
Expand Down