Skip to content

Commit

Permalink
Add support of 'custom_kernel_specs' parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
AnastasiaSliusar committed May 6, 2024
1 parent af1342d commit eba250f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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
8 changes: 7 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 @@ -282,8 +283,9 @@ async def create_session(
if kernel_id is not None and kernel_id in self.kernel_manager:
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 All @@ -306,6 +308,7 @@ def get_kernel_env(
Here the name is likely to be the name of the associated file
with the current kernel at startup time.
"""
#
if name is not None:
cwd = self.kernel_manager.cwd_for_path(path)
path = os.path.join(cwd, name)
Expand All @@ -319,6 +322,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 +339,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 kernek custom specifications
"""
# allow contents manager to specify kernels cwd
kernel_path = await ensure_async(self.contents_manager.get_kernel_path(path=path))
Expand Down

0 comments on commit eba250f

Please sign in to comment.