mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 06:22:59 +00:00
Make Spawner.env configurable
moves `_env_default` logic to `get_env`, so that `Spawner.env` can be safely configurable
This commit is contained in:
@@ -116,14 +116,9 @@ class Spawner(LoggingConfigurable):
|
|||||||
], config=True,
|
], config=True,
|
||||||
help="Whitelist of environment variables for the subprocess to inherit"
|
help="Whitelist of environment variables for the subprocess to inherit"
|
||||||
)
|
)
|
||||||
env = Dict()
|
env = Dict(config=True,
|
||||||
def _env_default(self):
|
help="Environment variables to load into the Spawner environment."
|
||||||
env = {}
|
)
|
||||||
for key in self.env_keep:
|
|
||||||
if key in os.environ:
|
|
||||||
env[key] = os.environ[key]
|
|
||||||
env['JPY_API_TOKEN'] = self.api_token
|
|
||||||
return env
|
|
||||||
|
|
||||||
cmd = Command(['jupyterhub-singleuser'], config=True,
|
cmd = Command(['jupyterhub-singleuser'], config=True,
|
||||||
help="""The command used for starting notebooks."""
|
help="""The command used for starting notebooks."""
|
||||||
@@ -204,12 +199,19 @@ class Spawner(LoggingConfigurable):
|
|||||||
self.api_token = ''
|
self.api_token = ''
|
||||||
|
|
||||||
def get_env(self):
|
def get_env(self):
|
||||||
"""Return the environment we should use
|
"""Return the environment dict to use for the Spawner.
|
||||||
|
|
||||||
|
This applies things like `env_keep`, anything defined in `Spawner.env`,
|
||||||
|
and adds the API token to the env.
|
||||||
|
|
||||||
Default returns a copy of self.env.
|
|
||||||
Use this to access the env in Spawner.start to allow extension in subclasses.
|
Use this to access the env in Spawner.start to allow extension in subclasses.
|
||||||
"""
|
"""
|
||||||
return self.env.copy()
|
env = self.env.copy()
|
||||||
|
for key in self.env_keep:
|
||||||
|
if key in os.environ:
|
||||||
|
env[key] = os.environ[key]
|
||||||
|
env['JPY_API_TOKEN'] = self.api_token
|
||||||
|
return env
|
||||||
|
|
||||||
def get_args(self):
|
def get_args(self):
|
||||||
"""Return the arguments to be passed after self.cmd"""
|
"""Return the arguments to be passed after self.cmd"""
|
||||||
|
Reference in New Issue
Block a user