Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of 'custom_kernel_specs' parameters #1

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
261bc30
Add parameter for configuring kernel specs (#87)
AnastasiaSliusar May 6, 2024
365ec7c
Merge branch 'main' into parametrizing_kernels
AnastasiaSliusar Jun 12, 2024
de64ec0
fix a typo
AnastasiaSliusar Jun 12, 2024
726d90c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 12, 2024
79e2953
Add switching parameter
AnastasiaSliusar Jun 24, 2024
6ff701a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 24, 2024
52d9da6
Update a parameter
AnastasiaSliusar Jun 26, 2024
fc564a4
Merge branch 'parametrizing_kernels' of https://github.com/AnastasiaS…
AnastasiaSliusar Jun 26, 2024
42314da
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 26, 2024
6dcee70
Update page config
AnastasiaSliusar Jun 28, 2024
3365b3a
Merge branch 'parametrizing_kernels' of https://github.com/AnastasiaS…
AnastasiaSliusar Jun 28, 2024
f1fc8c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
1c88856
Remove fail space
AnastasiaSliusar Jun 28, 2024
c6bb58e
Resolve conflics
AnastasiaSliusar Jun 28, 2024
d057fc8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 28, 2024
41a3a77
Clean code
AnastasiaSliusar Aug 1, 2024
03ebe01
Merge branch 'parametrizing_kernels' of https://github.com/AnastasiaS…
AnastasiaSliusar Aug 1, 2024
89e0bfa
Clean code
AnastasiaSliusar Aug 1, 2024
7f0ad3e
Merge branch 'main' into parametrizing_kernels
AnastasiaSliusar Aug 12, 2024
56b18aa
Remove custom page config handler
AnastasiaSliusar Aug 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,12 @@ def _default_allow_remote(self) -> bool:
""",
)

allow_insecure_kernelspec_params = Bool(
False,
config=True,
help="""Allow to use insecure kernelspec parameters""",
)

browser = Unicode(
"",
config=True,
Expand Down Expand Up @@ -2180,6 +2186,7 @@ def init_event_logger(self) -> None:
self.event_logger.register_event_schema(schema_path)

def init_webapp(self) -> None:
#
"""initialize tornado webapp"""
self.tornado_settings["allow_origin"] = self.allow_origin
self.tornado_settings["websocket_compression_options"] = self.websocket_compression_options
Expand Down Expand Up @@ -2991,7 +2998,6 @@ def target():
def start_app(self) -> None:
"""Start the Jupyter Server application."""
super().start()

if not self.allow_root:
# check if we are running as root, and abort if it's not allowed
try:
Expand Down Expand Up @@ -3030,6 +3036,10 @@ def start_app(self) -> None:
# Handle the browser opening.
if self.open_browser and not self.sock:
self.launch_browser()
if self.allow_insecure_kernelspec_params:
self.kernel_spec_manager.allow_insecure_kernelspec_params(
self.allow_insecure_kernelspec_params
)

if self.identity_provider.token and self.identity_provider.token_generated:
# log full URL with generated token, so there's a copy/pasteable link
Expand Down
10 changes: 10 additions & 0 deletions jupyter_server/services/sessions/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ async def post(self):
kernel = model.get("kernel", {})
kernel_name = kernel.get("name", None)
kernel_id = kernel.get("id", None)
custom_kernel_specs = kernel.get("custom_kernel_specs", {})

if not kernel_id and not kernel_name:
self.log.debug("No kernel specified, using default kernel")
Expand All @@ -93,6 +94,7 @@ async def post(self):
kernel_id=kernel_id,
name=name,
type=mtype,
custom_kernel_specs=custom_kernel_specs,
)
except NoSuchKernel:
msg = (
Expand Down Expand Up @@ -152,6 +154,9 @@ async def patch(self, session_id):
changes["name"] = model["name"]
if "type" in model:
changes["type"] = model["type"]
if "custom_kernel_specs" in model:
changes["custom_kernel_specs"] = model["custom_kernel_specs"]

if "kernel" in model:
# Kernel id takes precedence over name.
if model["kernel"].get("id") is not None:
Expand All @@ -160,13 +165,18 @@ async def patch(self, session_id):
raise web.HTTPError(400, "No such kernel: %s" % kernel_id)
changes["kernel_id"] = kernel_id
elif model["kernel"].get("name") is not None:
if "custom_kernel_specs" in model["kernel"]:
custom_kernel_specs = model["kernel"]["custom_kernel_specs"]
else:
custom_kernel_specs = None
kernel_name = model["kernel"]["name"]
kernel_id = await sm.start_kernel_for_session(
session_id,
kernel_name=kernel_name,
name=before["name"],
path=before["path"],
type=before["type"],
custom_kernel_specs=custom_kernel_specs,
)
changes["kernel_id"] = kernel_id

Expand Down
7 changes: 6 additions & 1 deletion jupyter_server/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ async def create_session(
type: Optional[str] = None,
kernel_name: Optional[KernelName] = None,
kernel_id: Optional[str] = None,
custom_kernel_specs: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
"""Creates a session and returns its model

Expand All @@ -283,7 +284,7 @@ async def create_session(
pass
else:
kernel_id = await self.start_kernel_for_session(
session_id, path, name, type, kernel_name
session_id, path, name, type, kernel_name, custom_kernel_specs
)
record.kernel_id = kernel_id
self._pending_sessions.update(record)
Expand Down Expand Up @@ -319,6 +320,7 @@ async def start_kernel_for_session(
name: Optional[ModelName],
type: Optional[str],
kernel_name: Optional[KernelName],
custom_kernel_specs: Optional[Dict[str, Any]] = None,
) -> str:
"""Start a new kernel for a given session.

Expand All @@ -335,6 +337,8 @@ async def start_kernel_for_session(
the type of the session
kernel_name : str
the name of the kernel specification to use. The default kernel name will be used if not provided.
custom_kernel_specs: dict
dictionary of kernel custom specifications
"""
# allow contents manager to specify kernels cwd
kernel_path = await ensure_async(self.contents_manager.get_kernel_path(path=path))
Expand All @@ -344,6 +348,7 @@ async def start_kernel_for_session(
path=kernel_path,
kernel_name=kernel_name,
env=kernel_env,
custom_kernel_specs=custom_kernel_specs,
)
return cast(str, kernel_id)

Expand Down