diff --git a/.github/workflows/downstream.yml b/.github/workflows/downstream.yml index 0d314fa44..ab1f10350 100644 --- a/.github/workflows/downstream.yml +++ b/.github/workflows/downstream.yml @@ -25,6 +25,20 @@ jobs: package_name: nbclient env_values: IPYKERNEL_CELL_NAME=\ + 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: @@ -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) }} diff --git a/ipykernel/comm/comm.py b/ipykernel/comm/comm.py index 97c2f1b86..f1fb0c88f 100644 --- a/ipykernel/comm/comm.py +++ b/ipykernel/comm/comm.py @@ -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 @@ -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) diff --git a/ipykernel/comm/manager.py b/ipykernel/comm/manager.py index 0314d6ffa..6bf73ad81 100644 --- a/ipykernel/comm/manager.py +++ b/ipykernel/comm/manager.py @@ -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)