Skip to content

Commit 4048071

Browse files
committed
Check if jupyter-client allows for external kernels
1 parent 1dcf0d3 commit 4048071

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

jupyter_server/serverapp.py

Lines changed: 23 additions & 14 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,25 @@ 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
1899+
kwargs = {
1900+
"parent": self,
1901+
"log": self.log,
1902+
"connection_dir": self.runtime_dir,
1903+
"kernel_spec_manager": self.kernel_spec_manager,
1904+
}
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+
kwargs["external_connection_dir"] = external_connection_dir
1911+
elif self.allow_external_kernels:
1912+
self.log.warning(
1913+
"Although allow_external_kernels=True, external kernels are not supported "
1914+
"because jupyter-client's version does not allow them (should be >8.3.0)."
1915+
)
19011916

1902-
self.kernel_manager = self.kernel_manager_class(
1903-
parent=self,
1904-
log=self.log,
1905-
connection_dir=self.runtime_dir,
1906-
external_connection_dir=external_connection_dir,
1907-
kernel_spec_manager=self.kernel_spec_manager,
1908-
)
1917+
self.kernel_manager = self.kernel_manager_class(**kwargs)
19091918
self.contents_manager = self.contents_manager_class(
19101919
parent=self,
19111920
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)