|
9 | 9 | from inspect import isawaitable |
10 | 10 | from typing import Any |
11 | 11 |
|
| 12 | +from packaging.version import parse as parse_version |
12 | 13 | from tornado.ioloop import IOLoop, PeriodicCallback |
13 | 14 |
|
14 | 15 | import dask.config |
@@ -493,14 +494,28 @@ def _repr_html_(self, cluster_status=None): |
493 | 494 | ) |
494 | 495 |
|
495 | 496 | def _ipython_display_(self, **kwargs): |
| 497 | + """Display the cluster rich IPython repr""" |
| 498 | + # Note: it would be simpler to just implement _repr_mimebundle_, |
| 499 | + # but we cannot do that until we drop ipywidgets 7 support, as |
| 500 | + # it does not provide a public way to get the mimebundle for a |
| 501 | + # widget. So instead we fall back on the more customizable _ipython_display_ |
| 502 | + # and display as a side-effect. |
| 503 | + from IPython.display import display |
| 504 | + |
496 | 505 | widget = self._widget() |
497 | | - if widget is not None: |
498 | | - return widget._ipython_display_(**kwargs) |
| 506 | + if widget: |
| 507 | + import ipywidgets |
| 508 | + |
| 509 | + if parse_version(ipywidgets.__version__) >= parse_version("8.0.0"): |
| 510 | + mimebundle = widget._repr_mimebundle_(**kwargs) or {} |
| 511 | + mimebundle["text/plain"] = repr(self) |
| 512 | + mimebundle["text/html"] = self._repr_html_() |
| 513 | + display(mimebundle, raw=True) |
| 514 | + else: |
| 515 | + display(widget, **kwargs) |
499 | 516 | else: |
500 | | - from IPython.display import display |
501 | | - |
502 | | - data = {"text/plain": repr(self), "text/html": self._repr_html_()} |
503 | | - display(data, raw=True) |
| 517 | + mimebundle = {"text/plain": repr(self), "text/html": self._repr_html_()} |
| 518 | + display(mimebundle, raw=True) |
504 | 519 |
|
505 | 520 | def __enter__(self): |
506 | 521 | return self.sync(self.__aenter__) |
|
0 commit comments