Skip to content

Commit

Permalink
Check if jupyter-client allows for external kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Aug 4, 2023
1 parent 66e7526 commit 4739d97
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
37 changes: 23 additions & 14 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from base64 import encodebytes
from pathlib import Path

import jupyter_client
from jupyter_client.kernelspec import KernelSpecManager
from jupyter_client.manager import KernelManager
from jupyter_client.session import Session
Expand Down Expand Up @@ -1644,7 +1645,10 @@ def _update_notebook_dir(self, change):
allow_none=True,
config=True,
help=_i18n(
"The directory to look at for external kernel connection files, if allow_external_kernels is True. Defaults to Jupyter runtime_dir/external_kernels."
"The directory to look at for external kernel connection files, if allow_external_kernels is True. "
"Defaults to Jupyter runtime_dir/external_kernels. "
"Make sure that this directory is not filled with left-over connection files, "
"that could result in unnecessary kernel manager creations."
),
)

Expand Down Expand Up @@ -1892,20 +1896,25 @@ def init_configurables(self):
parent=self,
)

if self.allow_external_kernels:
external_connection_dir = self.external_connection_dir
if external_connection_dir is None:
external_connection_dir = str(Path(self.runtime_dir) / "external_kernels")
else:
external_connection_dir = None
kwargs = {
"parent": self,
"log": self.log,
"connection_dir": self.runtime_dir,
"kernel_spec_manager": self.kernel_spec_manager,
}
if jupyter_client.version_info > (8, 3, 0):
if self.allow_external_kernels:
external_connection_dir = self.external_connection_dir
if external_connection_dir is None:
external_connection_dir = str(Path(self.runtime_dir) / "external_kernels")
kwargs["external_connection_dir"] = external_connection_dir
elif self.allow_external_kernels:
self.log.warning(
"Although allow_external_kernels=True, external kernels are not supported "
"because jupyter-client's version does not allow them (should be >8.3.0)."
)

self.kernel_manager = self.kernel_manager_class(
parent=self,
log=self.log,
connection_dir=self.runtime_dir,
external_connection_dir=external_connection_dir,
kernel_spec_manager=self.kernel_spec_manager,
)
self.kernel_manager = self.kernel_manager_class(**kwargs)
self.contents_manager = self.contents_manager_class(
parent=self,
log=self.log,
Expand Down
6 changes: 0 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@ build = "make -C docs html SPHINXOPTS='-W'"
api = "sphinx-apidoc -o docs/source/api -f -E jupyter_server */terminal jupyter_server/pytest_plugin.py"

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

[tool.hatch.envs.cov]
pre-install-commands = [
"pip install https://github.com/davidbrochart/jupyter_client/archive/external-kernels.zip"
]
features = ["test"]
dependencies = ["coverage[toml]", "pytest-cov"]
[tool.hatch.envs.cov.scripts]
Expand Down

0 comments on commit 4739d97

Please sign in to comment.