Skip to content

Commit

Permalink
Backport #981: Make it easier to pass custom env variables to kernel (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
divyansshhh authored Sep 26, 2022
1 parent 507c697 commit f8e122b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions 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 = self.contents_manager.get_kernel_path(path=path)
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 f8e122b

Please sign in to comment.