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 Comm interface for downstream users #1042

Merged
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