Skip to content
Closed
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions ipykernel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
from ._version import version_info, __version__, kernel_protocol_version_info, kernel_protocol_version
from .connect import *
# -*- coding: utf-8 -*-
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from ._version import (
version_info, __version__,
kernel_protocol_version_info, kernel_protocol_version
)
from .connect import *
4 changes: 4 additions & 0 deletions ipykernel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

if __name__ == '__main__':
from ipykernel import kernelapp as app
app.launch_new_instance()
4 changes: 4 additions & 0 deletions ipykernel/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

version_info = (4, 3, 0, 'dev')
__version__ = '.'.join(map(str, version_info))

Expand Down
7 changes: 5 additions & 2 deletions ipykernel/codeutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# Distributed under the terms of the Modified BSD License.

import warnings
warnings.warn("ipykernel.codeutil is deprecated. It has moved to ipyparallel.serialize", DeprecationWarning)
warnings.warn(
'ipykernel.codeutil is deprecated. It has moved to ipyparallel.serialize',
DeprecationWarning
)

import sys
import types
Expand All @@ -35,4 +38,4 @@ def reduce_code(co):
args.insert(1, co.co_kwonlyargcount)
return code_ctor, tuple(args)

copyreg.pickle(types.CodeType, reduce_code)
copyreg.pickle(types.CodeType, reduce_code)
4 changes: 4 additions & 0 deletions ipykernel/comm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from .manager import *
from .comm import *
21 changes: 12 additions & 9 deletions ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Base class for a Comm"""

# Copyright (c) IPython Development Team.
Expand Down Expand Up @@ -34,15 +35,17 @@ def _session_default(self):
return self.kernel.session

target_name = Unicode('comm')
target_module = Unicode(None, allow_none=True, help="""requirejs module from
which to load comm target.""")
target_module = Unicode(
None, allow_none=True,
help='requirejs module from which to load comm target.'
)

topic = Bytes()
def _topic_default(self):
return ('comm-%s' % self.comm_id).encode('ascii')

_open_data = Dict(help="data dict, if any, to be included in comm_open")
_close_data = Dict(help="data dict, if any, to be included in comm_close")
_open_data = Dict(help='data dict, if any, to be included in comm_open')
_close_data = Dict(help='data dict, if any, to be included in comm_close')

_msg_callback = Any()
_close_callback = Any()
Expand All @@ -52,7 +55,7 @@ def _topic_default(self):
def _comm_id_default(self):
return uuid.uuid4().hex

primary = Bool(True, help="Am I the primary or secondary Comm?")
primary = Bool(True, help='Am I the primary or secondary Comm?')

def __init__(self, target_name='', data=None, metadata=None, buffers=None, **kwargs):
if target_name:
Expand Down Expand Up @@ -93,8 +96,8 @@ def open(self, data=None, metadata=None, buffers=None):
data = self._open_data
comm_manager = getattr(self.kernel, 'comm_manager', None)
if comm_manager is None:
raise RuntimeError("Comms cannot be opened without a kernel "
"and a comm_manager attached to that kernel.")
raise RuntimeError('Comms cannot be opened without a kernel '
'and a comm_manager attached to that kernel.')

comm_manager.register_comm(self)
try:
Expand Down Expand Up @@ -151,13 +154,13 @@ def on_msg(self, callback):

def handle_close(self, msg):
"""Handle a comm_close message"""
self.log.debug("handle_close[%s](%s)", self.comm_id, msg)
self.log.debug('handle_close[%s](%s)', self.comm_id, msg)
if self._close_callback:
self._close_callback(msg)

def handle_msg(self, msg):
"""Handle a comm_msg message"""
self.log.debug("handle_msg[%s](%s)", self.comm_id, msg)
self.log.debug('handle_msg[%s](%s)', self.comm_id, msg)
if self._msg_callback:
if self.shell:
self.shell.events.trigger('pre_execute')
Expand Down
19 changes: 10 additions & 9 deletions ipykernel/comm/manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Base class to manage comms"""

# Copyright (c) IPython Development Team.
Expand Down Expand Up @@ -87,8 +88,8 @@ def get_comm(self, comm_id):
it will log messages if the comm cannot be found.
"""
if comm_id not in self.comms:
self.log.warn("No such comm: %s", comm_id)
self.log.debug("Current comms: %s", lazy_keys(self.comms))
self.log.warn('No such comm: %s', comm_id)
self.log.debug('Current comms: %s', lazy_keys(self.comms))
return
# call, because we store weakrefs
comm = self.comms[comm_id]
Expand All @@ -110,20 +111,20 @@ def comm_open(self, stream, ident, msg):
)
self.register_comm(comm)
if f is None:
self.log.error("No such comm target registered: %s", target_name)
self.log.error('No such comm target registered: %s', target_name)
else:
try:
f(comm, msg)
return
except Exception:
self.log.error("Exception opening comm with target: %s", target_name, exc_info=True)
self.log.error('Exception opening comm with target: %s', target_name, exc_info=True)

# Failure.
try:
comm.close()
except:
self.log.error("""Could not close comm during `comm_open` failure
clean-up. The comm may not have been opened yet.""", exc_info=True)
self.log.error('''Could not close comm during `comm_open` failure
clean-up. The comm may not have been opened yet.''', exc_info=True)

def comm_msg(self, stream, ident, msg):
"""Handler for comm_msg messages"""
Expand All @@ -136,7 +137,7 @@ def comm_msg(self, stream, ident, msg):
try:
comm.handle_msg(msg)
except Exception:
self.log.error("Exception in comm_msg for %s", comm_id, exc_info=True)
self.log.error('Exception in comm_msg for %s', comm_id, exc_info=True)

def comm_close(self, stream, ident, msg):
"""Handler for comm_close messages"""
Expand All @@ -145,14 +146,14 @@ def comm_close(self, stream, ident, msg):
comm = self.get_comm(comm_id)
if comm is None:
# no such comm
self.log.debug("No such comm to close: %s", comm_id)
self.log.debug('No such comm to close: %s', comm_id)
return
del self.comms[comm_id]

try:
comm.handle_close(msg)
except Exception:
self.log.error("Exception handling comm_close for %s", comm_id, exc_info=True)
self.log.error('Exception handling comm_close for %s', comm_id, exc_info=True)


__all__ = ['CommManager']
41 changes: 27 additions & 14 deletions ipykernel/connect.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-
"""Connection file-related utilities for the kernel
"""

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

Expand All @@ -19,7 +21,6 @@
from jupyter_client import write_connection_file



def get_connection_file(app=None):
"""Return the path to the connection file of an app

Expand All @@ -31,15 +32,15 @@ def get_connection_file(app=None):
if app is None:
from ipykernel.kernelapp import IPKernelApp
if not IPKernelApp.initialized():
raise RuntimeError("app not specified, and not in a running Kernel")
raise RuntimeError('app not specified, and not in a running Kernel')

app = IPKernelApp.instance()
return filefind(app.connection_file, ['.', app.connection_dir])


def find_connection_file(filename='kernel-*.json', profile=None):
"""DEPRECATED: find a connection file, and return its absolute path.

THIS FUNCION IS DEPRECATED. Use juptyer_client.find_connection_file instead.

Parameters
Expand All @@ -54,10 +55,13 @@ def find_connection_file(filename='kernel-*.json', profile=None):
-------
str : The absolute path of the connection file.
"""

import warnings
warnings.warn("""ipykernel.find_connection_file is deprecated, use jupyter_client.find_connection_file""",
DeprecationWarning, stacklevel=2)
warnings.warn(
'ipykernel.find_connection_file is deprecated,'
' use jupyter_client.find_connection_file',
DeprecationWarning, stacklevel=2
)
from IPython.core.application import BaseIPythonApplication as IPApp
try:
# quick check for absolute path, before going through logic
Expand All @@ -72,18 +76,27 @@ def find_connection_file(filename='kernel-*.json', profile=None):
profile_dir = app.profile_dir
else:
# not running in IPython, use default profile
profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), 'default')
profile_dir = ProfileDir.find_profile_dir_by_name(
get_ipython_dir(),
'default'
)
else:
# find profiledir by profile name:
profile_dir = ProfileDir.find_profile_dir_by_name(get_ipython_dir(), profile)
profile_dir = ProfileDir.find_profile_dir_by_name(
get_ipython_dir(),
profile
)
security_dir = profile_dir.security_dir

return jupyter_client.find_connection_file(filename, path=['.', security_dir])

return jupyter_client.find_connection_file(
filename,
path=['.', security_dir]
)


def _find_connection_file(connection_file, profile=None):
"""Return the absolute path for a connection file

- If nothing specified, return current Kernel's connection file
- If profile specified, show deprecation warning about finding connection files in profiles
- Otherwise, call jupyter_client.find_connection_file
Expand All @@ -95,7 +108,7 @@ def _find_connection_file(connection_file, profile=None):
# connection file specified, allow shortnames:
if profile is not None:
warnings.warn(
"Finding connection file by profile is deprecated.",
'Finding connection file by profile is deprecated.',
DeprecationWarning, stacklevel=3,
)
return find_connection_file(connection_file, profile=profile)
Expand Down Expand Up @@ -165,8 +178,8 @@ def connect_qtconsole(connection_file=None, argv=None, profile=None):
cf = _find_connection_file(connection_file, profile)

cmd = ';'.join([
"from IPython.qt.console import qtconsoleapp",
"qtconsoleapp.main()"
'from IPython.qt.console import qtconsoleapp',
'qtconsoleapp.main()'
])

return Popen([sys.executable, '-c', cmd, '--existing', cf] + argv,
Expand Down
13 changes: 10 additions & 3 deletions ipykernel/datapub.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-
"""Publishing native (typically pickled) objects.
"""

import warnings
warnings.warn("ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub", DeprecationWarning)
warnings.warn(
'ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub',
DeprecationWarning
)

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Expand Down Expand Up @@ -56,7 +60,10 @@ def publish_data(data):
data : dict
The data to be published. Think of it as a namespace.
"""
warnings.warn("ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub", DeprecationWarning)

warnings.warn(
'ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub',
DeprecationWarning
)

from ipykernel.zmqshell import ZMQInteractiveShell
ZMQInteractiveShell.instance().data_pub.publish_data(data)
7 changes: 5 additions & 2 deletions ipykernel/displayhook.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Replacements for sys.displayhook that publish over ZMQ."""

# Copyright (c) IPython Development Team.
Expand Down Expand Up @@ -29,8 +30,10 @@ def __call__(self, obj):
builtin_mod._ = obj
sys.stdout.flush()
sys.stderr.flush()
self.session.send(self.pub_socket, u'execute_result', {u'data':repr(obj)},
parent=self.parent_header, ident=self.topic)
self.session.send(
self.pub_socket, u'execute_result', {u'data':repr(obj)},
parent=self.parent_header, ident=self.topic
)

def set_parent(self, parent):
self.parent_header = extract_header(parent)
Expand Down
5 changes: 5 additions & 0 deletions ipykernel/embed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# -*- coding: utf-8 -*-
"""Simple function for embedding an IPython kernel
"""

# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
Expand Down
Loading