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

Initial steps towards compatibility with IPython 4.0 (Jupyter) #144

Closed
wants to merge 1 commit into from
Closed
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
48 changes: 34 additions & 14 deletions ftplugin/python/vim_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,17 @@ def new_ipy(s=''):
new_ipy()

"""
from IPython.kernel import KernelManager

try:
from jupyter_client.manager import KernelManager
except ImportError: # For compatibility with IPython 3 or lower
from IPython.kernel import KernelManager

km = KernelManager()
km.start_kernel()
return km_from_string(km.connection_file)


def km_from_string(s=''):
"""create kernel manager from IPKernelApp string
such as '--shell=47378 --iopub=39859 --stdin=36778 --hb=52668' for IPython 0.11
Expand All @@ -107,21 +113,31 @@ 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.manager import KernelManager
from jupyter_client.connect import 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

Expand All @@ -142,7 +158,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")
Expand Down