Skip to content

Commit

Permalink
Fix Comm interface for downstream users (#1042)
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 <steven.silvester@ieee.org>
Fixes #1040
  • Loading branch information
maartenbreddels committed Nov 29, 2022
1 parent 8f54589 commit c0f5b7e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ jobs:
package_name: nbclient
env_values: IPYKERNEL_CELL_NAME=\<IPY-INPUT\>

ipywidgets:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

- name: Run Test
uses: jupyterlab/maintainer-tools/.github/actions/downstream-test@v1
with:
package_name: ipywidgets

jupyter_client:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -69,3 +83,18 @@ jobs:
cd jupyter_kernel_test
pip install -e ".[test]"
python test_ipykernel.py
downstream_check: # This job does nothing and is only used for the branch protection
if: always()
needs:
- nbclient
- ipywidgets
- jupyter_client
- ipyparallel
- jupyter_kernel_test
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
26 changes: 25 additions & 1 deletion ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import uuid
from typing import Optional

import comm.base_comm
import traitlets.config
from traitlets import Bool, Bytes, Instance, Unicode, default

from ipykernel.jsonutil import json_clean
from ipykernel.kernelbase import Kernel
Expand Down Expand Up @@ -43,8 +45,30 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
class Comm(traitlets.config.LoggingConfigurable, BaseComm):
"""Class for communicating between a Frontend and a Kernel"""

kernel = Instance("ipykernel.kernelbase.Kernel", allow_none=True) # type:ignore[assignment]
comm_id = Unicode()
primary = Bool(True, help="Am I the primary or secondary Comm?")

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

topic = Bytes()

@default("kernel")
def _default_kernel(self):
if Kernel.initialized():
return Kernel.instance()

@default("comm_id")
def _default_comm_id(self):
return uuid.uuid4().hex

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)
Expand Down
6 changes: 6 additions & 0 deletions ipykernel/comm/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@


import comm.base_comm
import traitlets
import traitlets.config


class CommManager(traitlets.config.LoggingConfigurable, comm.base_comm.CommManager):

kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")
comms = traitlets.Dict()
targets = traitlets.Dict()

def __init__(self, **kwargs):
# CommManager doesn't take arguments, so we explicitly forward arguments
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
Expand Down

0 comments on commit c0f5b7e

Please sign in to comment.