From 40a7c8fa5b4b27327ca1b9429432903c91d8b138 Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Fri, 28 Oct 2022 07:56:41 -0700 Subject: [PATCH 1/2] Include button for launching jupyterlab layout in repr --- distributed/client.py | 9 +++++++++ distributed/widgets/templates/client.html.j2 | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/distributed/client.py b/distributed/client.py index 4036a889f2b..a50a8eae3bd 100644 --- a/distributed/client.py +++ b/distributed/client.py @@ -1145,6 +1145,14 @@ def __repr__(self): return f"<{self.__class__.__name__}: No scheduler connected>" def _repr_html_(self): + try: + import dask_labextension # noqa: F401 + + # TODO: also guard with version check + JUPYTERLAB = True + except ImportError: + JUPYTERLAB = False + scheduler, info = self._get_scheduler_info() return get_template("client.html.j2").render( @@ -1154,6 +1162,7 @@ def _repr_html_(self): cluster=self.cluster, scheduler_file=self.scheduler_file, dashboard_link=self.dashboard_link, + jupyterlab=JUPYTERLAB, ) def start(self, **kwargs): diff --git a/distributed/widgets/templates/client.html.j2 b/distributed/widgets/templates/client.html.j2 index ad1c2e509ed..8a490acdd0b 100644 --- a/distributed/widgets/templates/client.html.j2 +++ b/distributed/widgets/templates/client.html.j2 @@ -29,6 +29,12 @@ + {% if jupyterlab %} + + {% endif %} + {% if scheduler is none %}

No scheduler connected.

{% elif cluster %} From 87e2dfe866a1ddc74a31bf2bbc4b138a38f02d2c Mon Sep 17 00:00:00 2001 From: Ian Rose Date: Fri, 4 Nov 2022 11:16:58 -0700 Subject: [PATCH 2/2] Use importlib instead of defensive import --- distributed/client.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/distributed/client.py b/distributed/client.py index a50a8eae3bd..7eadf9448c0 100644 --- a/distributed/client.py +++ b/distributed/client.py @@ -22,10 +22,12 @@ from contextlib import contextmanager, suppress from contextvars import ContextVar from functools import partial +from importlib.metadata import PackageNotFoundError, version from numbers import Number from queue import Queue as pyQueue from typing import Any, ClassVar, Coroutine, Literal, Sequence, TypedDict +from packaging.version import parse as parse_version from tlz import first, groupby, keymap, merge, partition_all, valmap import dask @@ -1146,11 +1148,9 @@ def __repr__(self): def _repr_html_(self): try: - import dask_labextension # noqa: F401 - - # TODO: also guard with version check - JUPYTERLAB = True - except ImportError: + dle_version = parse_version(version("dask-labextension")) + JUPYTERLAB = False if dle_version < parse_version("6.0.0") else True + except PackageNotFoundError: JUPYTERLAB = False scheduler, info = self._get_scheduler_info()