From 212dd05b4e38ebd1568a6a05dea97c53a8a54257 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 17 Apr 2024 14:21:50 -0400 Subject: [PATCH 1/2] BUG: imjoy-jupyterlab-extension dep with notebook>=7 JupyterLab extensions server both JupyterLab>=4 and the Jupyter notebook>=7 with JupyterLab>=4. Our updated imjoy-jupyterlab-extension supports both. --- itkwidgets/integrations/environment.py | 22 ++++++++-------------- pyproject.toml | 3 +-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/itkwidgets/integrations/environment.py b/itkwidgets/integrations/environment.py index c09b13fd..0b976b85 100644 --- a/itkwidgets/integrations/environment.py +++ b/itkwidgets/integrations/environment.py @@ -38,22 +38,16 @@ def find_env(): if ENVIRONMENT is not Env.JUPYTERLITE and ENVIRONMENT is not Env.HYPHA: if ENVIRONMENT is not Env.COLAB: - if ENVIRONMENT is Env.JUPYTER_NOTEBOOK and sys.version_info.minor > 7: - try: - import imjoy_jupyter_extension - except: - raise RuntimeError('imjoy-jupyter-extension is required. `pip install itkwidgets[notebook]` and refresh page.') - else: + try: + import_module("imjoy-jupyterlab-extension") + except ModuleNotFoundError: try: - import_module("imjoy-jupyterlab-extension") + import_module("imjoy_jupyterlab_extension") except ModuleNotFoundError: - try: - import_module("imjoy_jupyterlab_extension") - except ModuleNotFoundError: - if ENVIRONMENT is Env.JUPYTERLITE: - raise RuntimeError('imjoy-jupyterlab-extension is required. Install the package and refresh page.') - elif sys.version_info.minor > 7: - raise RuntimeError('imjoy-jupyterlab-extension is required. `pip install itkwidgets[lab]` and refresh page.') + if ENVIRONMENT is Env.JUPYTERLITE: + raise RuntimeError('imjoy-jupyterlab-extension is required. Install the package and refresh page.') + elif sys.version_info.minor > 7: + raise RuntimeError('imjoy-jupyterlab-extension is required. `pip install itkwidgets[lab]` and refresh page.') try: import imjoy_elfinder diff --git a/pyproject.toml b/pyproject.toml index 0873b296..51cab183 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,7 +64,6 @@ Source = "https://github.com/InsightSoftwareConsortium/itkwidgets" all = [ "imjoy-jupyterlab-extension", "imjoy-elfinder[jupyter]", - "imjoy-jupyter-extension", "aiohttp <4.0" ] lab = [ @@ -82,7 +81,7 @@ cli = [ ] notebook = [ - "imjoy-jupyter-extension >=0.3.0", + "imjoy-jupyterlab-extension", "imjoy-elfinder[jupyter]" ] test = [ From d9b45856ace9b2be7835866417df98a2c3e5a542 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Wed, 17 Apr 2024 14:52:53 -0400 Subject: [PATCH 2/2] ENH: Add check for sufficient notebook or jupyterlab version --- itkwidgets/integrations/environment.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/itkwidgets/integrations/environment.py b/itkwidgets/integrations/environment.py index 0b976b85..ffc84549 100644 --- a/itkwidgets/integrations/environment.py +++ b/itkwidgets/integrations/environment.py @@ -1,5 +1,7 @@ from enum import Enum from importlib import import_module +from packaging import version +import importlib_metadata import sys @@ -28,7 +30,6 @@ def find_env(): else: return Env.SAGEMAKER except: - import sys if sys.platform == 'emscripten': return Env.JUPYTERLITE return Env.HYPHA @@ -38,6 +39,15 @@ def find_env(): if ENVIRONMENT is not Env.JUPYTERLITE and ENVIRONMENT is not Env.HYPHA: if ENVIRONMENT is not Env.COLAB: + if ENVIRONMENT is Env.JUPYTER_NOTEBOOK: + notebook_version = importlib_metadata.version('notebook') + if version.parse(notebook_version) < version.parse('7'): + raise RuntimeError('itkwidgets 1.0a51 and newer requires Jupyter notebook>=7.') + elif ENVIRONMENT is Env.JUPYTERLAB: + lab_version = importlib_metadata.version('jupyterlab') + if version.parse(lab_version) < version.parse('4'): + raise RuntimeError('itkwidgets 1.0a51 and newer requires jupyterlab>=4.') + try: import_module("imjoy-jupyterlab-extension") except ModuleNotFoundError: