Skip to content

Commit 3022a11

Browse files
committed
Initial steps towards compatibility with IPython 4.0 (Jupyter)
Signed-off-by: David DeTomaso <[email protected]>
1 parent 42499f0 commit 3022a11

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

ftplugin/python/vim_ipython.py

+34-14
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,17 @@ def new_ipy(s=''):
9393
new_ipy()
9494
9595
"""
96-
from IPython.kernel import KernelManager
96+
97+
try:
98+
from jupyter_client.manager import KernelManager
99+
except ImportError: # For compatibility with IPython 3 or lower
100+
from IPython.kernel import KernelManager
101+
97102
km = KernelManager()
98103
km.start_kernel()
99104
return km_from_string(km.connection_file)
100105

106+
101107
def km_from_string(s=''):
102108
"""create kernel manager from IPKernelApp string
103109
such as '--shell=47378 --iopub=39859 --stdin=36778 --hb=52668' for IPython 0.11
@@ -107,21 +113,31 @@ def km_from_string(s=''):
107113
import IPython
108114
except ImportError:
109115
raise ImportError("Could not find IPython. " + _install_instructions)
110-
from IPython.config.loader import KeyValueConfigLoader
116+
111117
try:
112-
from IPython.kernel import (
113-
KernelManager,
114-
find_connection_file,
115-
)
116-
except ImportError:
117-
# IPython < 1.0
118-
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
119-
from IPython.zmq.kernelapp import kernel_aliases
118+
from traitlets.config.loader import KeyValueConfigLoader
119+
except ImportError: # IPython <= 3.0
120+
from IPython.config.loader import KeyValueConfigLoader
121+
122+
try:
123+
from jupyter_client.manager import KernelManager
124+
from jupyter_client.connect import find_connection_file
125+
126+
except ImportError: # IPython <= 3.0
120127
try:
121-
from IPython.lib.kernel import find_connection_file
128+
from IPython.kernel import (
129+
KernelManager,
130+
find_connection_file,
131+
)
122132
except ImportError:
123-
# < 0.12, no find_connection_file
124-
pass
133+
# IPython < 1.0
134+
from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager
135+
from IPython.zmq.kernelapp import kernel_aliases
136+
try:
137+
from IPython.lib.kernel import find_connection_file
138+
except ImportError:
139+
# < 0.12, no find_connection_file
140+
pass
125141

126142
global km, kc, send
127143

@@ -142,7 +158,11 @@ def km_from_string(s=''):
142158
p = p.lstrip().rstrip() # profile part of the string
143159
fullpath = find_connection_file(k,p)
144160
else:
145-
fullpath = find_connection_file(s.lstrip().rstrip())
161+
s = s.lstrip().rstrip();
162+
if(len(s) == 0):
163+
fullpath = find_connection_file()
164+
else:
165+
fullpath = find_connection_file(s.lstrip().rstrip())
146166
except IOError as e:
147167
echo(":IPython " + s + " failed", "Info")
148168
echo("^-- failed '" + s + "' not found", "Error")

0 commit comments

Comments
 (0)