Skip to content

Commit c0f5b7e

Browse files
maartenbreddelspre-commit-ci[bot]blink1073
authored
Fix Comm interface for downstream users (#1042)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Steven Silvester <[email protected]> Fixes #1040
1 parent 8f54589 commit c0f5b7e

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

.github/workflows/downstream.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ jobs:
2525
package_name: nbclient
2626
env_values: IPYKERNEL_CELL_NAME=\<IPY-INPUT\>
2727

28+
ipywidgets:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
34+
- name: Base Setup
35+
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
36+
37+
- name: Run Test
38+
uses: jupyterlab/maintainer-tools/.github/actions/downstream-test@v1
39+
with:
40+
package_name: ipywidgets
41+
2842
jupyter_client:
2943
runs-on: ubuntu-latest
3044
steps:
@@ -69,3 +83,18 @@ jobs:
6983
cd jupyter_kernel_test
7084
pip install -e ".[test]"
7185
python test_ipykernel.py
86+
87+
downstream_check: # This job does nothing and is only used for the branch protection
88+
if: always()
89+
needs:
90+
- nbclient
91+
- ipywidgets
92+
- jupyter_client
93+
- ipyparallel
94+
- jupyter_kernel_test
95+
runs-on: ubuntu-latest
96+
steps:
97+
- name: Decide whether the needed jobs succeeded or failed
98+
uses: re-actors/alls-green@release/v1
99+
with:
100+
jobs: ${{ toJSON(needs) }}

ipykernel/comm/comm.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
# Copyright (c) IPython Development Team.
44
# Distributed under the terms of the Modified BSD License.
55

6+
import uuid
67
from typing import Optional
78

89
import comm.base_comm
910
import traitlets.config
11+
from traitlets import Bool, Bytes, Instance, Unicode, default
1012

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

48+
kernel = Instance("ipykernel.kernelbase.Kernel", allow_none=True) # type:ignore[assignment]
49+
comm_id = Unicode()
50+
primary = Bool(True, help="Am I the primary or secondary Comm?")
51+
52+
target_name = Unicode("comm")
53+
target_module = Unicode(
54+
None,
55+
allow_none=True,
56+
help="""requirejs module from
57+
which to load comm target.""",
58+
)
59+
60+
topic = Bytes()
61+
62+
@default("kernel")
63+
def _default_kernel(self):
64+
if Kernel.initialized():
65+
return Kernel.instance()
66+
67+
@default("comm_id")
68+
def _default_comm_id(self):
69+
return uuid.uuid4().hex
70+
4671
def __init__(self, *args, **kwargs):
47-
self.kernel = None
4872
# Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments
4973
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
5074
BaseComm.__init__(self, *args, **kwargs)

ipykernel/comm/manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66

77
import comm.base_comm
8+
import traitlets
89
import traitlets.config
910

1011

1112
class CommManager(traitlets.config.LoggingConfigurable, comm.base_comm.CommManager):
13+
14+
kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")
15+
comms = traitlets.Dict()
16+
targets = traitlets.Dict()
17+
1218
def __init__(self, **kwargs):
1319
# CommManager doesn't take arguments, so we explicitly forward arguments
1420
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)

0 commit comments

Comments
 (0)