Skip to content

Commit 0925d09

Browse files
authored
Fix comms and add qtconsole downstream test (#1056)
Fixes #1059
1 parent 04e1d75 commit 0925d09

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

.github/workflows/downstream.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,41 @@ jobs:
8484
pip install -e ".[test]"
8585
python test_ipykernel.py
8686
87+
qtconsole:
88+
runs-on: ubuntu-latest
89+
timeout-minutes: 20
90+
steps:
91+
- name: Checkout
92+
uses: actions/checkout@v3
93+
94+
- name: Setup Python
95+
uses: actions/setup-python@v4
96+
with:
97+
python-version: "3.9"
98+
architecture: "x64"
99+
100+
- name: Install System Packages
101+
run: |
102+
sudo apt-get update
103+
sudo apt-get install -y --no-install-recommends '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
104+
- name: Install qtconsole dependencies
105+
shell: bash -l {0}
106+
run: |
107+
cd ${GITHUB_WORKSPACE}/..
108+
git clone https://github.com/jupyter/qtconsole.git
109+
cd qtconsole
110+
${pythonLocation}/bin/python -m pip install -e ".[test]"
111+
${pythonLocation}/bin/python -m pip install pyqt5
112+
- name: Install Jupyter-Client changes
113+
shell: bash -l {0}
114+
run: ${pythonLocation}/bin/python -m pip install -e .
115+
116+
- name: Test qtconsole
117+
shell: bash -l {0}
118+
run: |
119+
cd ${GITHUB_WORKSPACE}/../qtconsole
120+
xvfb-run --auto-servernum ${pythonLocation}/bin/python -m pytest -x -vv -s --full-trace --color=yes qtconsole
121+
87122
downstream_check: # This job does nothing and is only used for the branch protection
88123
if: always()
89124
needs:
@@ -92,6 +127,7 @@ jobs:
92127
- jupyter_client
93128
- ipyparallel
94129
- jupyter_kernel_test
130+
- qtconsole
95131
runs-on: ubuntu-latest
96132
steps:
97133
- name: Decide whether the needed jobs succeeded or failed

ipykernel/comm/comm.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):
4242

4343

4444
# but for backwards compatibility, we need to inherit from LoggingConfigurable
45-
class Comm(traitlets.config.LoggingConfigurable, BaseComm):
45+
class Comm(BaseComm, traitlets.config.LoggingConfigurable):
4646
"""Class for communicating between a Frontend and a Kernel"""
4747

4848
kernel = Instance("ipykernel.kernelbase.Kernel", allow_none=True) # type:ignore[assignment]
@@ -68,12 +68,16 @@ def _default_kernel(self):
6868
def _default_comm_id(self):
6969
return uuid.uuid4().hex
7070

71-
def __init__(self, *args, **kwargs):
72-
# Comm takes positional arguments, LoggingConfigurable does not, so we explicitly forward arguments
71+
def __init__(self, target_name='', data=None, metadata=None, buffers=None, **kwargs):
72+
# Handle differing arguments between base classes.
73+
kernel = kwargs.pop('kernel', None)
74+
if target_name:
75+
kwargs['target_name'] = target_name
76+
BaseComm.__init__(
77+
self, data=data, metadata=metadata, buffers=buffers, **kwargs
78+
) # type:ignore[call-arg]
79+
kwargs['kernel'] = kernel
7380
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
74-
# drop arguments not in BaseComm
75-
kwargs.pop("kernel", None)
76-
BaseComm.__init__(self, *args, **kwargs)
7781

7882

7983
__all__ = ["Comm"]

ipykernel/comm/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import traitlets.config
1010

1111

12-
class CommManager(traitlets.config.LoggingConfigurable, comm.base_comm.CommManager):
12+
class CommManager(comm.base_comm.CommManager, traitlets.config.LoggingConfigurable):
1313

1414
kernel = traitlets.Instance("ipykernel.kernelbase.Kernel")
1515
comms = traitlets.Dict()
1616
targets = traitlets.Dict()
1717

1818
def __init__(self, **kwargs):
1919
# CommManager doesn't take arguments, so we explicitly forward arguments
20-
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)
2120
comm.base_comm.CommManager.__init__(self)
21+
traitlets.config.LoggingConfigurable.__init__(self, **kwargs)

ipykernel/tests/test_comm.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import unittest.mock
2+
13
from ipykernel.comm import Comm, CommManager
24
from ipykernel.ipkernel import IPythonKernel
35

@@ -47,10 +49,12 @@ def on_msg(msg):
4749
manager.register_target("fizz", fizz)
4850

4951
kernel.comm_manager = manager
50-
comm = Comm()
51-
comm.on_msg(on_msg)
52-
comm.on_close(on_close)
53-
manager.register_comm(comm)
52+
with unittest.mock.patch.object(Comm, "publish_msg") as publish_msg:
53+
comm = Comm()
54+
comm.on_msg(on_msg)
55+
comm.on_close(on_close)
56+
manager.register_comm(comm)
57+
assert publish_msg.call_count == 1
5458

5559
assert manager.get_comm(comm.comm_id) == comm
5660
assert manager.get_comm('foo') is None

0 commit comments

Comments
 (0)