Skip to content

Commit ef88cc0

Browse files
author
Benjamin van der Burgh
committed
Utilize Jupyter for instantiating a kernel connection in IPython >= 4
1 parent 42499f0 commit ef88cc0

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

ftplugin/python/vim_ipython.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ def new_ipy(s=''):
9393
new_ipy()
9494
9595
"""
96-
from IPython.kernel import KernelManager
96+
try:
97+
from jupyter_client.manager import KernelManager
98+
except ImportError:
99+
from IPython.kernel import KernelManager
97100
km = KernelManager()
98101
km.start_kernel()
99102
return km_from_string(km.connection_file)
@@ -107,21 +110,28 @@ def km_from_string(s=''):
107110
import IPython
108111
except ImportError:
109112
raise ImportError("Could not find IPython. " + _install_instructions)
110-
from IPython.config.loader import KeyValueConfigLoader
111113
try:
112-
from IPython.kernel import (
113-
KernelManager,
114-
find_connection_file,
115-
)
114+
from traitlets.config.loader import KeyValueConfigLoader
115+
except ImportError:
116+
from IPython.config.loader import KeyValueConfigLoader
117+
try:
118+
from jupyter_client.manager import KernelManager
119+
from jupyter_client.connect import find_connection_file
116120
except ImportError:
117-
# IPython < 1.0
118-
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
119-
from IPython.zmq.kernelapp import kernel_aliases
120121
try:
121-
from IPython.lib.kernel import find_connection_file
122+
from IPython.kernel import (
123+
KernelManager,
124+
find_connection_file,
125+
)
122126
except ImportError:
123-
# < 0.12, no find_connection_file
124-
pass
127+
# IPython < 1.0
128+
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
129+
from IPython.zmq.kernelapp import kernel_aliases
130+
try:
131+
from IPython.lib.kernel import find_connection_file
132+
except ImportError:
133+
# < 0.12, no find_connection_file
134+
pass
125135

126136
global km, kc, send
127137

@@ -147,8 +157,13 @@ def km_from_string(s=''):
147157
echo(":IPython " + s + " failed", "Info")
148158
echo("^-- failed '" + s + "' not found", "Error")
149159
return
150-
km = KernelManager(connection_file = fullpath)
151-
km.load_connection_file()
160+
if IPython.version_info[0] >= 4:
161+
km = KernelManager()
162+
km.connection_file = find_connection_file()
163+
km.load_connection_file()
164+
else:
165+
km = KernelManager(connection_file = fullpath)
166+
km.load_connection_file()
152167
else:
153168
if s == '':
154169
echo(":IPython 0.11 requires the full connection string")

0 commit comments

Comments
 (0)