|
10 | 10 | from contextlib import contextmanager
|
11 | 11 | from collections.abc import Iterable
|
12 | 12 | from IPython import get_ipython
|
13 |
| -from ipykernel.comm import Comm |
14 | 13 | from traitlets import (
|
15 |
| - HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, |
| 14 | + Any, HasTraits, Unicode, Dict, Instance, List, Int, Set, Bytes, observe, default, Container, |
16 | 15 | Undefined)
|
17 | 16 | from json import loads as jsonloads, dumps as jsondumps
|
18 | 17 |
|
@@ -480,7 +479,7 @@ def get_view_spec(self):
|
480 | 479 |
|
481 | 480 | _view_count = Int(None, allow_none=True,
|
482 | 481 | help="EXPERIMENTAL: The number of views of the model displayed in the frontend. This attribute is experimental and may change or be removed in the future. None signifies that views will not be tracked. Set this to 0 to start tracking view creation/deletion.").tag(sync=True)
|
483 |
| - comm = Instance('ipykernel.comm.Comm', allow_none=True) |
| 482 | + comm = Any(None, allow_none=True) |
484 | 483 |
|
485 | 484 | keys = List(help="The traits which are synced.")
|
486 | 485 |
|
@@ -525,7 +524,15 @@ def open(self):
|
525 | 524 | if self._model_id is not None:
|
526 | 525 | args['comm_id'] = self._model_id
|
527 | 526 |
|
528 |
| - self.comm = Comm(**args) |
| 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 | 536 |
|
530 | 537 | @observe('comm')
|
531 | 538 | def _comm_changed(self, change):
|
@@ -686,7 +693,7 @@ def notify_change(self, change):
|
686 | 693 | # Send the state to the frontend before the user-registered callbacks
|
687 | 694 | # are called.
|
688 | 695 | name = change['name']
|
689 |
| - if self.comm is not None and self.comm.kernel is not None: |
| 696 | + if self.comm is not None: |
690 | 697 | # Make sure this isn't information that the front-end just sent us.
|
691 | 698 | if name in self.keys and self._should_send_property(name, getattr(self, name)):
|
692 | 699 | # Send new state to front-end
|
@@ -814,7 +821,7 @@ def _repr_mimebundle_(self, **kwargs):
|
814 | 821 |
|
815 | 822 | def _send(self, msg, buffers=None):
|
816 | 823 | """Sends a message to the model in the front-end."""
|
817 |
| - if self.comm is not None and self.comm.kernel is not None: |
| 824 | + if self.comm is not None: |
818 | 825 | self.comm.send(data=msg, buffers=buffers)
|
819 | 826 |
|
820 | 827 | def _repr_keys(self):
|
|
0 commit comments