Skip to content

Commit c7e4d1b

Browse files
committed
Check if jupyter-client allows for external kernels
1 parent 8e2f7b5 commit c7e4d1b

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

jupyter_server/serverapp.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from base64 import encodebytes
2727
from pathlib import Path
2828

29+
import jupyter_client
2930
from jupyter_client.kernelspec import KernelSpecManager
3031
from jupyter_client.manager import KernelManager
3132
from jupyter_client.session import Session
@@ -1644,7 +1645,10 @@ def _update_notebook_dir(self, change):
16441645
allow_none=True,
16451646
config=True,
16461647
help=_i18n(
1647-
"The directory to look at for external kernel connection files, if allow_external_kernels is True. Defaults to Jupyter runtime_dir/external_kernels."
1648+
"The directory to look at for external kernel connection files, if allow_external_kernels is True. "
1649+
"Defaults to Jupyter runtime_dir/external_kernels. "
1650+
"Make sure that this directory is not filled with left-over connection files, "
1651+
"that could result in unnecessary kernel manager creations."
16481652
),
16491653
)
16501654

@@ -1892,20 +1896,28 @@ def init_configurables(self):
18921896
parent=self,
18931897
)
18941898

1895-
if self.allow_external_kernels:
1896-
external_connection_dir = self.external_connection_dir
1897-
if external_connection_dir is None:
1898-
external_connection_dir = str(Path(self.runtime_dir) / "external_kernels")
1899-
else:
1900-
external_connection_dir = None
1901-
1902-
self.kernel_manager = self.kernel_manager_class(
1899+
kwargs = dict(
19031900
parent=self,
19041901
log=self.log,
19051902
connection_dir=self.runtime_dir,
1906-
external_connection_dir=external_connection_dir,
19071903
kernel_spec_manager=self.kernel_spec_manager,
19081904
)
1905+
if jupyter_client.version_info > (8, 3, 0):
1906+
if self.allow_external_kernels:
1907+
external_connection_dir = self.external_connection_dir
1908+
if external_connection_dir is None:
1909+
external_connection_dir = str(Path(self.runtime_dir) / "external_kernels")
1910+
else:
1911+
external_connection_dir = None
1912+
1913+
kwargs.update(external_connection_dir=external_connection_dir)
1914+
elif self.allow_external_kernels:
1915+
self.log.warning(
1916+
"Although allow_external_kernels=True, external kernels are not supported "
1917+
"because jupyter-client's version does not allow them (should be >8.3.0)."
1918+
)
1919+
1920+
self.kernel_manager = self.kernel_manager_class(**kwargs)
19091921
self.contents_manager = self.contents_manager_class(
19101922
parent=self,
19111923
log=self.log,

pyproject.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ build = "make -C docs html SPHINXOPTS='-W'"
9797
api = "sphinx-apidoc -o docs/source/api -f -E jupyter_server */terminal jupyter_server/pytest_plugin.py"
9898

9999
[tool.hatch.envs.test]
100-
pre-install-commands = [
101-
"pip install https://github.com/davidbrochart/jupyter_client/archive/external-kernels.zip"
102-
]
103100
features = ["test"]
104101
[tool.hatch.envs.test.scripts]
105102
test = "python -m pytest -vv {args}"
@@ -112,9 +109,6 @@ dependencies = [ "mypy>=0.990" ]
112109
test = "mypy --install-types --non-interactive {args:.}"
113110

114111
[tool.hatch.envs.cov]
115-
pre-install-commands = [
116-
"pip install https://github.com/davidbrochart/jupyter_client/archive/external-kernels.zip"
117-
]
118112
features = ["test"]
119113
dependencies = ["coverage[toml]", "pytest-cov"]
120114
[tool.hatch.envs.cov.scripts]

0 commit comments

Comments
 (0)