From c4056a5ede3210d1ab7fa83026101f7941c031ef Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Tue, 25 Jan 2022 16:58:33 +0100 Subject: [PATCH] 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 https://github.com/jupyter/jupyter_client/pull/656, https://github.com/jupyter/notebook/pull/6180. It will need to be ported to jupyter_server as well. This is the mirror commit of https://github.com/jupyter/notebook/pull/6279 on main notebook. --- jupyter_server/services/sessions/sessionmanager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jupyter_server/services/sessions/sessionmanager.py b/jupyter_server/services/sessions/sessionmanager.py index c3c6edc7ef..d1d61dbf46 100644 --- a/jupyter_server/services/sessions/sessionmanager.py +++ b/jupyter_server/services/sessions/sessionmanager.py @@ -138,7 +138,9 @@ async def start_kernel_for_session(self, session_id, path, name, type, kernel_na # allow contents manager to specify kernels cwd kernel_path = self.contents_manager.get_kernel_path(path=path) kernel_id = await self.kernel_manager.start_kernel( - path=kernel_path, kernel_name=kernel_name + path=kernel_path, + kernel_name=kernel_name, + env={"JPY_SESSION_NAME": str(pathlib.Path(path).resolve())}, ) return kernel_id