Skip to content

Commit

Permalink
Make it easier to pass custom env variables to kernel (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
divyansshhh authored Sep 22, 2022
1 parent a4266be commit 98b4285
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion jupyter_server/services/sessions/sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,19 @@ async def create_session(
self._pending_sessions.remove(record)
return result

def get_kernel_env(self, path):
"""Return the environment variables that need to be set in the kernel"""
return {**os.environ, "JPY_SESSION_NAME": path}

async def start_kernel_for_session(self, session_id, path, name, type, kernel_name):
"""Start a new kernel for a given session."""
# allow contents manager to specify kernels cwd
kernel_path = await ensure_async(self.contents_manager.get_kernel_path(path=path))
kernel_env = self.get_kernel_env(path)
kernel_id = await self.kernel_manager.start_kernel(
path=kernel_path,
kernel_name=kernel_name,
env={**os.environ, "JPY_SESSION_NAME": path},
env=kernel_env,
)
return kernel_id

Expand Down

0 comments on commit 98b4285

Please sign in to comment.