Skip to content

Commit b330020

Browse files
Merge pull request #3811 from martinRenou/add_comm_dependency
Replace ipykernel dependency by the comm dependency
2 parents 39d3c5d + 2ef7e16 commit b330020

File tree

8 files changed

+50
-28
lines changed

8 files changed

+50
-28
lines changed

.github/workflows/devinstall.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
2929
- name: Install dependencies
3030
run: |
31-
python -m pip install notebook jupyterlab jupyter_packaging~=0.10
31+
python -m pip install notebook jupyterlab notebook~=6.0 jupyter_packaging~=0.10
3232
- name: Run the dev-install script
3333
run: |
3434
./dev-install.sh

dev-install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jlpm build
3131
echo -n "widgetsnbextension"
3232
pip install -v -e ./python/widgetsnbextension
3333
if [[ "$OSTYPE" == "msys" ]]; then
34-
jupyter nbextension install --overwrite --py $nbExtFlags widgetsnbextension
34+
jupyter nbextension install --overwrite --py $nbExtFlags widgetsnbextension || true
3535
else
36-
jupyter nbextension install --overwrite --py --symlink $nbExtFlags widgetsnbextension
36+
jupyter nbextension install --overwrite --py --symlink $nbExtFlags widgetsnbextension || true
3737
fi
38-
jupyter nbextension enable --py $nbExtFlags widgetsnbextension
38+
jupyter nbextension enable --py $nbExtFlags widgetsnbextension || true
3939

4040
echo -n "ipywidgets"
4141
pip install -v -e "./python/ipywidgets[test]"

docs/source/examples/Widget Custom.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
{
44
"cell_type": "markdown",
55
"metadata": {
6-
"tags": ["remove-cell"]
6+
"tags": [
7+
"remove-cell"
8+
]
79
},
810
"source": [
911
"[Index](Index.ipynb) - [Back](Widget%20Styling.ipynb) - [Next](Widget%20Asynchronous.ipynb)"
@@ -828,7 +830,9 @@
828830
{
829831
"cell_type": "markdown",
830832
"metadata": {
831-
"tags": ["remove-cell"]
833+
"tags": [
834+
"remove-cell"
835+
]
832836
},
833837
"source": [
834838
"[Index](Index.ipynb) - [Back](Widget%20Styling.ipynb) - [Next](Widget%20Asynchronous.ipynb)"

python/ipywidgets/ipywidgets/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,10 @@
2121
from ._version import __version__, __protocol_version__, __jupyter_widgets_controls_version__, __jupyter_widgets_base_version__
2222

2323
import os
24+
import sys
2425

2526
from traitlets import link, dlink
2627
from IPython import get_ipython
27-
try:
28-
from comm import get_comm_manager
29-
except ImportError:
30-
def get_comm_manager():
31-
ip = get_ipython()
32-
33-
if ip is not None and getattr(ip, "kernel", None) is not None:
34-
return get_ipython().kernel.comm_manager
3528

3629
from .widgets import *
3730

@@ -44,7 +37,8 @@ def load_ipython_extension(ip):
4437

4538
def register_comm_target(kernel=None):
4639
"""Register the jupyter.widget comm target"""
47-
comm_manager = get_comm_manager()
40+
from . import comm
41+
comm_manager = comm.get_comm_manager()
4842
if comm_manager is None:
4943
return
5044
comm_manager.register_target('jupyter.widget', Widget.handle_comm_opened)

python/ipywidgets/ipywidgets/comm.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# compatibility shim for ipykernel < 6.18
2+
import sys
3+
from IPython import get_ipython
4+
import comm
5+
6+
7+
def requires_ipykernel_shim():
8+
if "ipykernel" in sys.modules:
9+
import ipykernel
10+
11+
version = ipykernel.version_info
12+
return version < (6, 18)
13+
else:
14+
return False
15+
16+
17+
def get_comm_manager():
18+
if requires_ipykernel_shim():
19+
ip = get_ipython()
20+
21+
if ip is not None and getattr(ip, "kernel", None) is not None:
22+
return get_ipython().kernel.comm_manager
23+
else:
24+
return comm.get_comm_manager()
25+
26+
27+
def create_comm(*args, **kwargs):
28+
if requires_ipykernel_shim():
29+
from ipykernel.comm import Comm
30+
31+
return Comm(*args, **kwargs)
32+
else:
33+
return comm.create_comm(*args, **kwargs)

python/ipywidgets/ipywidgets/tests/test_embed.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
import traitlets
1111

12-
# This has a byproduct of setting up the comms
13-
import ipykernel.ipkernel
14-
1512
from ..widgets import IntSlider, IntText, Text, Widget, jslink, HBox, widget_serialization, widget as widget_module
1613
from ..embed import embed_data, embed_snippet, embed_minimal_html, dependency_state
1714

python/ipywidgets/ipywidgets/widgets/widget.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
in the Jupyter notebook front-end.
77
"""
88
import os
9+
import sys
910
import typing
1011
from contextlib import contextmanager
1112
from collections.abc import Iterable
@@ -14,6 +15,7 @@
1415
Any, HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container,
1516
Undefined)
1617
from json import loads as jsonloads, dumps as jsondumps
18+
from .. import comm
1719

1820
from base64 import standard_b64encode
1921

@@ -524,15 +526,7 @@ def open(self):
524526
if self._model_id is not None:
525527
args['comm_id'] = self._model_id
526528

527-
try:
528-
from comm import create_comm
529-
except ImportError:
530-
def create_comm(**kwargs):
531-
from ipykernel.comm import Comm
532-
533-
return Comm(**kwargs)
534-
535-
self.comm = create_comm(**args)
529+
self.comm = comm.create_comm(**args)
536530

537531
@observe('comm')
538532
def _comm_changed(self, change):

python/ipywidgets/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ zip_safe = False
3434
packages = find:
3535

3636
install_requires =
37-
ipykernel>=4.5.1
37+
comm>=0.1.3
3838
ipython>=6.1.0
3939
traitlets>=4.3.1
4040
widgetsnbextension~=4.0.7

0 commit comments

Comments
 (0)