@@ -51,26 +51,43 @@ except NameError:
51
51
52
52
def km_from_string (s ):
53
53
" ""create kernel manager from IPKernelApp string
54
- such as ' --shell=47378 --iopub=39859 --stdin=36778 --hb=52668'
54
+ such as ' --shell=47378 --iopub=39859 --stdin=36778 --hb=52668' for 0.11
55
+ or just ' kernel-12345.json' for 0.12
55
56
" ""
57
+ from os.path import join as pjoin
56
58
from IPython.zmq.blockingkernelmanager import BlockingKernelManager, Empty
57
59
from IPython.config.loader import KeyValueConfigLoader
58
60
from IPython.zmq.kernelapp import kernel_aliases
59
61
global km ,send,Empty
60
- # vim interface currently only deals with existing kernels
61
- s = s .replace (' --existing' ,' ' )
62
- loader = KeyValueConfigLoader (s .split (), aliases= kernel_aliases)
63
- cfg = loader.load_config ()[' KernelApp' ]
64
- try :
65
- km = BlockingKernelManager (
66
- shell_address= (ip, cfg[' shell_port' ]),
67
- sub_address= (ip, cfg[' iopub_port' ]),
68
- stdin_address= (ip, cfg[' stdin_port' ]),
69
- hb_address= (ip, cfg[' hb_port' ]))
70
- except KeyError,e :
71
- echo (" :IPython " + s + " failed" , " Info" )
72
- echo (" ^-- failed --" + e .message.replace (' _port' ,' ' )+ " not specified" , " Error" )
73
- return
62
+
63
+ if ' connection_file' in BlockingKernelManager.class_trait_names ():
64
+ from IPython.lib.kernel import find_connection_file
65
+ # 0.12 uses files instead of a collection of ports
66
+ # include default IPython search path
67
+ # filefind also allows for absolute paths, in which case the search
68
+ # is ignored
69
+ try :
70
+ fullpath = find_connection_file (s )
71
+ except IOError,e :
72
+ echo (" :IPython " + s + " failed" , " Info" )
73
+ echo (" ^-- failed --" + s + " not found" , " Error" )
74
+ return
75
+ km = BlockingKernelManager (connection_file = fullpath)
76
+ km .load_connection_file ()
77
+ else :
78
+ s = s .replace (' --existing' , ' ' )
79
+ loader = KeyValueConfigLoader (s .split (), aliases= kernel_aliases)
80
+ cfg = loader.load_config ()[' KernelApp' ]
81
+ try :
82
+ km = BlockingKernelManager (
83
+ shell_address= (ip, cfg[' shell_port' ]),
84
+ sub_address= (ip, cfg[' iopub_port' ]),
85
+ stdin_address= (ip, cfg[' stdin_port' ]),
86
+ hb_address= (ip, cfg[' hb_port' ]))
87
+ except KeyError,e :
88
+ echo (" :IPython " + s + " failed" , " Info" )
89
+ echo (" ^-- failed --" + e .message.replace (' _port' ,' ' )+ " not specified" , " Error" )
90
+ return
74
91
km .start_channels ()
75
92
send = km .shell_channel.execute
76
93
return km
@@ -170,7 +187,8 @@ def update_subchannel_msgs(debug=False):
170
187
db = vim .current.buffer
171
188
else :
172
189
db = []
173
- startedin_vimipython = vim .current.buffer .name.endswith (' vim-ipython' )
190
+ b = vim .current.buffer
191
+ startedin_vimipython = (b .name is not None and b .name.endswith (' vim-ipython' ))
174
192
if not startedin_vimipython:
175
193
vim .command (" pcl" )
176
194
vim .command (" silent pedit vim-ipython" )
0 commit comments