Skip to content

Commit

Permalink
fix: use comm package in backwards compatible way (ipython#1028)
Browse files Browse the repository at this point in the history
* fix: use comm package in backwards compatible way

* feat: do not use the LoggingConfigurable class in create_comm

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Steven Silvester <steven.silvester@ieee.org>
  • Loading branch information
3 people committed Nov 24, 2022
1 parent 747259c commit c5a045f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
3 changes: 1 addition & 2 deletions ipykernel/comm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
__all__ = ["Comm", "CommManager"]

from comm.base_comm import CommManager # noqa

from .comm import Comm # noqa
from .manager import CommManager
26 changes: 18 additions & 8 deletions ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from comm.base_comm import BaseComm
from typing import Optional

import comm.base_comm
import traitlets.config

from ipykernel.jsonutil import json_clean
from ipykernel.kernelbase import Kernel


class Comm(BaseComm):
"""Class for communicating between a Frontend and a Kernel"""

def __init__(self, *args, **kwargs):
self.kernel = None

super().__init__(*args, **kwargs)
# this is the class that will be created if we do comm.create_comm
class BaseComm(comm.base_comm.BaseComm):
kernel: Optional[Kernel]

def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
"""Helper for sending a comm message on IOPub"""
Expand All @@ -40,4 +39,15 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
)


# but for backwards compatibility, we need to inherit from LoggingConfigurable
class Comm(traitlets.config.LoggingConfigurable, BaseComm):
"""Class for communicating between a Frontend and a Kernel"""

def __init__(self, *args, **kwargs):
self.kernel = None
# Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
BaseComm.__init__(self, *args, **kwargs)


__all__ = ["Comm"]
11 changes: 10 additions & 1 deletion ipykernel/comm/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

from comm.base_comm import CommManager # noqa

import comm.base_comm
import traitlets.config


class CommManager(traitlets.config.LoggingConfigurable, comm.base_comm.CommManager):
def __init__(self, **kwargs):
# CommManager doesn't take arguments, so we explicitly forward arguments
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
comm.base_comm.CommManager.__init__(self)
4 changes: 2 additions & 2 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from traitlets import Any, Bool, Instance, List, Type, observe, observe_compat
from zmq.eventloop.zmqstream import ZMQStream

from .comm import Comm
from .comm.comm import BaseComm
from .compiler import XCachingCompiler
from .debugger import Debugger, _is_debugpy_available
from .eventloops import _use_appnope
Expand All @@ -42,7 +42,7 @@

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


comm.create_comm = create_comm
Expand Down

0 comments on commit c5a045f

Please sign in to comment.