Skip to content

Commit 4b3a390

Browse files
vidartfCarreaupre-commit-ci[bot]
authored
Backport Inject session identifier into environment variable. #679 (#920)
* Inject session identifier into environment variable. There are many use case where users want to know the current notebook name/path. This help by adding a session identifier (to not really say this is the current notebook name), and by default make it the full path to the notebook document that created the session. This will of course not work if the notebook get renamed, but we can tackle this later. See also jupyter/jupyter_client#656, jupyter/notebook#6180. It will need to be ported to jupyter_server as well. This is the mirror commit of jupyter/notebook#6279 on main notebook. * Make start_kernel env extend os.environ (#859) * Make start_kernel env extend os.environ * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Matthias Bussonnier <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c9897b5 commit 4b3a390

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

jupyter_server/services/sessions/sessionmanager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""A base class session manager."""
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
4+
import os
45
import pathlib
56
import uuid
67

@@ -272,7 +273,9 @@ async def start_kernel_for_session(self, session_id, path, name, type, kernel_na
272273
# allow contents manager to specify kernels cwd
273274
kernel_path = self.contents_manager.get_kernel_path(path=path)
274275
kernel_id = await self.kernel_manager.start_kernel(
275-
path=kernel_path, kernel_name=kernel_name
276+
path=kernel_path,
277+
kernel_name=kernel_name,
278+
env={**os.environ, "JPY_SESSION_NAME": path},
276279
)
277280
return kernel_id
278281

0 commit comments

Comments
 (0)