Allow configuring default notebook interface from config.yaml

Also fix bug in how overrides were being done in config.yaml
This commit is contained in:
yuvipanda
2018-06-29 00:47:08 -07:00
parent a7e58626dd
commit 78c9be32ab

View File

@@ -26,20 +26,25 @@ default = {
'limits': {
'memory': '1G',
'cpu': None
},
'userEnvironment': {
'defaultApp': 'classic'
}
}
def apply_yaml_config(path, c):
if os.path.exists(path):
with open(path) as f:
tljh_config = _merge_dictionaries(yaml.safe_load(f), default)
tljh_config = _merge_dictionaries(default, yaml.safe_load(f))
else:
tljh_config = copy.deepcopy(default)
update_auth(c, tljh_config)
update_userlists(c, tljh_config)
update_limits(c, tljh_config)
update_user_environment(c, tljh_config)
def update_auth(c, config):
@@ -77,6 +82,19 @@ def update_limits(c, config):
c.SystemdSpawner.cpu_limit = limits['cpu']
def update_user_environment(c, config):
"""
Set user environment configuration
"""
user_env = config['userEnvironment']
# Set default application users are launched into
if user_env['defaultApp'] == 'jupyterlab':
c.Spawner.default_url = '/lab'
elif user_env['defaultApp'] == 'nteract':
c.Spawner.default_url = '/nteract'
def _merge_dictionaries(a, b, path=None, update=True):
"""
Merge two dictionaries recursively.