Merge pull request #479 from minrk/config-env

Make Spawner.env configurable
This commit is contained in:
Carol Willing
2016-03-24 07:59:44 -07:00

View File

@@ -116,14 +116,15 @@ 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(help="""Deprecated: use Spawner.get_env or Spawner.environment
def _env_default(self):
env = {} - extend Spawner.get_env for adding required env in Spawner subclasses
for key in self.env_keep: - Spawner.environment for config-specified env
if key in os.environ: """)
env[key] = os.environ[key]
env['JPY_API_TOKEN'] = self.api_token environment = Dict(config=True,
return env help="Environment variables to load for the Spawner."
)
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 +205,27 @@ 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.
Default returns a copy of self.env. This applies things like `env_keep`, anything defined in `Spawner.environment`,
and adds the API token to the 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 = {}
if self.env:
warnings.warn("Spawner.env is deprecated, found %s" % self.env, DeprecationWarning)
env.update(self.env)
for key in self.env_keep:
if key in os.environ:
env[key] = os.environ[key]
# config overrides
env.update(self.environment)
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"""