Skip to content

Commit

Permalink
Configurables needs to be configurable (#1037)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steven Silvester <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2022
1 parent e7aecf5 commit a38167b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 20 additions & 3 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@
import comm
from IPython.core import release
from IPython.utils.tokenutil import line_at_cursor, token_at_cursor
from traitlets import Any, Bool, Instance, List, Type, observe, observe_compat
from traitlets import (
Any,
Bool,
HasTraits,
Instance,
List,
Type,
observe,
observe_compat,
)
from zmq.eventloop.zmqstream import ZMQStream

from .comm.comm import BaseComm
from .comm.manager import CommManager
from .compiler import XCachingCompiler
from .debugger import Debugger, _is_debugpy_available
from .eventloops import _use_appnope
Expand All @@ -40,12 +50,18 @@
_EXPERIMENTAL_KEY_NAME = "_jupyter_types_experimental"


def create_comm(*args, **kwargs):
def _create_comm(*args, **kwargs):
"""Create a new Comm."""
return BaseComm(*args, **kwargs)


comm.create_comm = create_comm
def _get_comm_manager(*args, **kwargs):
"""Create a new CommManager."""
return CommManager(*args, **kwargs)


comm.create_comm = _create_comm
comm.get_comm_manager = _get_comm_manager


class IPythonKernel(KernelBase):
Expand Down Expand Up @@ -112,6 +128,7 @@ def __init__(self, **kwargs):

self.comm_manager = comm.get_comm_manager()

assert isinstance(self.comm_manager, HasTraits)
self.shell.configurables.append(self.comm_manager)
comm_msg_types = ["comm_open", "comm_msg", "comm_close"]
for msg_type in comm_msg_types:
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/tests/test_ipkernel_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import zmq
from IPython.core.history import DummyDB

from ipykernel.ipkernel import BaseComm, IPythonKernel, create_comm
from ipykernel.ipkernel import BaseComm, IPythonKernel, _create_comm

from .conftest import MockIPyKernel

Expand Down Expand Up @@ -187,7 +187,7 @@ async def fake_poll_control_queue():


def test_create_comm():
assert isinstance(create_comm(), BaseComm)
assert isinstance(_create_comm(), BaseComm)


def test_finish_metadata(ipkernel: IPythonKernel):
Expand Down

0 comments on commit a38167b

Please sign in to comment.