diff --git a/README.rst b/README.rst index 26e556a..1b4bab8 100644 --- a/README.rst +++ b/README.rst @@ -2,9 +2,9 @@ vim-ipython ########### -A two-way integration between Vim and IPython. +A two-way integration between Vim and IPython/Jupyter. -IPython versions 0.11.x, 0.12.x, 0.13.x, 1.x, 2.x and 3.x +IPython/Jupyter versions 0.11.x, 0.12.x, 0.13.x, 1.x, 2.x, 3.x, 4.x * author: Paul Ivanov (http://pirsquared.org) * github: http://github.com/ivanov/vim-ipython @@ -294,6 +294,7 @@ pull request with your attribution. * @pydave for IPythonTerminate (sending SIGTERM using our hack) * @luispedro for IPythonNew * @jjhelmus and @wmvanvliet for IPython 3.x support. +* @jjhelmus and @deto for IPython/Jupyter 4.x support. Similar Projects ---------------- diff --git a/ftplugin/python/vim_ipython.py b/ftplugin/python/vim_ipython.py index 0a4ed08..f7b5a53 100644 --- a/ftplugin/python/vim_ipython.py +++ b/ftplugin/python/vim_ipython.py @@ -93,7 +93,10 @@ def new_ipy(s=''): new_ipy() """ - from IPython.kernel import KernelManager + try: + from jupyter_client import KernelManager + except ImportError: # for compatability with IPython 3 or lower + from IPython.kernel import KernelManager km = KernelManager() km.start_kernel() return km_from_string(km.connection_file) @@ -107,21 +110,26 @@ 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, - ) - except ImportError: - # IPython < 1.0 - from IPython.zmq.blockingkernelmanager import BlockingKernelManager as KernelManager - from IPython.zmq.kernelapp import kernel_aliases + from traitlets.config.loader import KeyValueConfigLoader + except ImportError: # IPython <= 3.0 + from IPython.config.loader import KeyValueConfigLoader + + try: + from jupyter_client import KernelManager, find_connection_file + except ImportError: # IPython <= 3.0 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 @@ -142,7 +150,11 @@ def km_from_string(s=''): p = p.lstrip().rstrip() # profile part of the string fullpath = find_connection_file(k,p) else: - fullpath = find_connection_file(s.lstrip().rstrip()) + s = s.lstrip().rstrip() + if len(s) == 0: + fullpath = find_connection_file() + else: + fullpath = find_connection_file(s.lstrip().rstrip()) except IOError as e: echo(":IPython " + s + " failed", "Info") echo("^-- failed '" + s + "' not found", "Error") @@ -232,7 +244,10 @@ def disconnect(): def get_doc(word, level=0): if kc is None: return ["Not connected to IPython, cannot query: %s" % word] - msg_id = kc.shell_channel.object_info(word, level) + if hasattr(kc, 'inspect'): # IPython/Jupyter 4.x + msg_id = kc.inspect(word, None, level) + else: # IPython <= 3 + msg_id = kc.shell_channel.object_info(word, level) doc = get_doc_msg(msg_id) # get around unicode problems when interfacing with vim return [d.encode(vim_encoding) for d in doc] @@ -320,8 +335,11 @@ def get_doc_buffer(level=0): def ipy_complete(base, current_line, pos): # pos is the location of the start of base, add the length # to get the completion position - msg_id = kc.shell_channel.complete(base, current_line, - int(pos) + len(base) - 1) + if hasattr(kc, 'complete'): + msg_id = kc.complete(current_line, int(pos) + len(base) - 1) + else: + msg_id = kc.shell_channel.complete(base, current_line, + int(pos) + len(base) - 1) try: m = get_child_msg(msg_id) matches = m['content']['matches']