mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
add load_config top-level function to configurer
for easy loading of the full config
This commit is contained in:
@@ -7,6 +7,13 @@ be called many times per lifetime of a jupyterhub.
|
|||||||
Traitlets that modify the startup of JupyterHub should not be here.
|
Traitlets that modify the startup of JupyterHub should not be here.
|
||||||
FIXME: A strong feeling that JSON Schema should be involved somehow.
|
FIXME: A strong feeling that JSON Schema should be involved somehow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
INSTALL_PREFIX = os.environ.get('TLJH_INSTALL_PREFIX', '/opt/tljh')
|
||||||
|
CONFIG_FILE = os.path.join(INSTALL_PREFIX, 'config.yaml')
|
||||||
|
|
||||||
# Default configuration for tljh
|
# Default configuration for tljh
|
||||||
# User provided config is merged into this
|
# User provided config is merged into this
|
||||||
default = {
|
default = {
|
||||||
@@ -32,6 +39,19 @@ default = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(config_file=CONFIG_FILE):
|
||||||
|
"""Load the current config as a dictionary
|
||||||
|
|
||||||
|
merges overrides from config.yaml with default config
|
||||||
|
"""
|
||||||
|
if os.path.exists(config_file):
|
||||||
|
with open(config_file) as f:
|
||||||
|
config_overrides = yaml.safe_load(f)
|
||||||
|
else:
|
||||||
|
config_overrides = {}
|
||||||
|
return _merge_dictionaries(dict(default), config_overrides)
|
||||||
|
|
||||||
|
|
||||||
def apply_config(config_overrides, c):
|
def apply_config(config_overrides, c):
|
||||||
"""
|
"""
|
||||||
Merge config_overrides with config defaults & apply to JupyterHub config c
|
Merge config_overrides with config defaults & apply to JupyterHub config c
|
||||||
|
|||||||
Reference in New Issue
Block a user