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

Fix: Inherit from LoggingConfigurable #6

Closed
wants to merge 3 commits into from
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
4 changes: 2 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ jobs:
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Install and test
run:
run: |
pip install -e .[test]
pytest
pytest .
11 changes: 7 additions & 4 deletions comm/base_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import logging

from traitlets.utils.importstring import import_item
from traitlets.config import LoggingConfigurable

logger = logging.getLogger('Comm')



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

Must be subclassed with a publish_msg method implementation which
Expand Down Expand Up @@ -92,7 +93,6 @@ def open(self, data=None, metadata=None, buffers=None):

def close(self, data=None, metadata=None, buffers=None, deleting=False):
"""Close the frontend-side version of this comm"""
from comm import get_comm_manager
if self._closed:
# only close once
return
Expand All @@ -107,6 +107,7 @@ def close(self, data=None, metadata=None, buffers=None, deleting=False):
)
if not deleting:
# If deleting, the comm can't be registered
from comm import get_comm_manager
get_comm_manager().unregister_comm(self)

def send(self, data=None, metadata=None, buffers=None):
Expand Down Expand Up @@ -160,15 +161,17 @@ def handle_msg(self, msg):
shell.events.trigger("post_execute")


class CommManager:
class CommManager(LoggingConfigurable):
"""Default CommManager singleton implementation for Comms in the Kernel"""

# Public APIs

def __init__(self):
def __init__(self, *args, **kwargs):
self.comms = {}
self.targets = {}

super(CommManager, self).__init__(*args, **kwargs)

def register_target(self, target_name, f):
"""Register a callable f for a given target name

Expand Down
15 changes: 14 additions & 1 deletion tests/test_comm.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from traitlets import Any
from traitlets.config import LoggingConfigurable

from comm.base_comm import CommManager, BaseComm


Expand All @@ -7,11 +10,21 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
pass


class CustomCommManager(CommManager):

parent = Any()


def test_comm_manager():
test = CommManager()
assert test.targets == {}


def test_base_comm():
test = MyComm()
assert test.target_name == "comm"
assert test.target_name == "comm"


def test_custom_comm_manager():
test = CustomCommManager(parent=LoggingConfigurable())
assert test.parent is not None