Skip to content

Commit

Permalink
ENH: Consolidate JUPYTERLAB and JUPYTER_NOTEBOOK Env's into JUPYTER
Browse files Browse the repository at this point in the history
With Jupyter Lab 4 / Jupyter Notebook 7, we cannot detect the difference
and there is not a difference in how we deal with them.
  • Loading branch information
thewtex committed Apr 18, 2024
1 parent e1b2ddc commit aed23d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/integrations/dask/DaskArray.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"ENVIRONMENT: Env.JUPYTERLAB\n"
"ENVIRONMENT: Env.JUPYTER\n"
]
}
],
Expand Down
31 changes: 17 additions & 14 deletions itkwidgets/integrations/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@


class Env(Enum):
JUPYTER_NOTEBOOK = 'notebook'
JUPYTERLAB = 'lab'
JUPYTER = 'jupyter'
JUPYTERLITE = 'lite'
SAGEMAKER = 'sagemaker'
HYPHA = 'hypha'
Expand All @@ -24,9 +23,7 @@ def find_env():
parent_header = get_ipython().parent_header
username = parent_header['header']['username']
if username == '':
return Env.JUPYTERLAB
elif username == 'username':
return Env.JUPYTER_NOTEBOOK
return Env.JUPYTER
else:
return Env.SAGEMAKER
except:
Expand All @@ -39,15 +36,21 @@ 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.')

if ENVIRONMENT is Env.JUPYTER:
try:
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.')
except importlib_metadata.PackageNotFoundError:
# notebook may not be available
pass
try:
lab_version = importlib_metadata.version('jupyterlab')
if version.parse(lab_version) < version.parse('4'):
raise RuntimeError('itkwidgets 1.0a51 and newer requires jupyterlab>=4.')
except importlib_metadata.PackageNotFoundError:
# jupyterlab may not be available
pass
try:
import_module("imjoy-jupyterlab-extension")
except ModuleNotFoundError:
Expand Down

0 comments on commit aed23d4

Please sign in to comment.