Skip to content

Commit

Permalink
Replace ipykernel dependency by the comm dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jul 26, 2023
1 parent 39d3c5d commit 49e9036
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
10 changes: 7 additions & 3 deletions python/ipywidgets/ipywidgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@
from ._version import __version__, __protocol_version__, __jupyter_widgets_controls_version__, __jupyter_widgets_base_version__

import os
import sys

from traitlets import link, dlink
from IPython import get_ipython
try:
from comm import get_comm_manager
except ImportError:

# ipykernel <6.18 when the comm package did not exist
if "ipykernel" in sys.modules and "comm" not in sys.modules:
def get_comm_manager():
ip = get_ipython()

if ip is not None and getattr(ip, "kernel", None) is not None:
return get_ipython().kernel.comm_manager
# Using the comm package
else:
from comm import get_comm_manager

from .widgets import *

Expand Down
8 changes: 5 additions & 3 deletions python/ipywidgets/ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
in the Jupyter notebook front-end.
"""
import os
import sys
import typing
from contextlib import contextmanager
from collections.abc import Iterable
Expand Down Expand Up @@ -524,13 +525,14 @@ def open(self):
if self._model_id is not None:
args['comm_id'] = self._model_id

try:
from comm import create_comm
except ImportError:
# ipykernel <6.18 when the comm package did not exist
if "ipykernel" in sys.modules and "comm" not in sys.modules:
def create_comm(**kwargs):
from ipykernel.comm import Comm

return Comm(**kwargs)
else:
from comm import create_comm

self.comm = create_comm(**args)

Expand Down
2 changes: 1 addition & 1 deletion python/ipywidgets/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ zip_safe = False
packages = find:

install_requires =
ipykernel>=4.5.1
comm>=0.1.3
ipython>=6.1.0
traitlets>=4.3.1
widgetsnbextension~=4.0.7
Expand Down

0 comments on commit 49e9036

Please sign in to comment.