forked from cylc/cylc-uiserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjupyter_config.py
More file actions
106 lines (93 loc) · 3.59 KB
/
jupyter_config.py
File metadata and controls
106 lines (93 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright (C) NIWA & British Crown (Met Office) & Contributors.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Configuration file for jupyterhub.
from importlib.resources import files
from pathlib import Path
from cylc.uiserver import (
__file__ as uis_pkg,
getenv,
)
from cylc.uiserver.app import USER_CONF_ROOT
from cylc.uiserver.authorise import CylcAuthorizer
# the command the hub should spawn (i.e. the cylc uiserver itself)
c.Spawner.cmd = ['cylc', 'hubapp']
# the spawner to invoke this command
c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'
# environment variables to pass to the spawner (if defined)
c.Spawner.environment = getenv(
# site config path override
'CYLC_SITE_CONF_PATH',
# used to specify the Cylc version if using a wrapper script
'CYLC_VERSION',
'CYLC_ENV_NAME',
# may be used by Cylc UI developers to use a development UI build
'CYLC_DEV',
)
# this auto-spawns uiservers without user interaction
c.JupyterHub.implicit_spawn_seconds = 0.01
# apply cylc styling to jupyterhub
c.JupyterHub.logo_file = str(Path(uis_pkg).parent / 'logo.svg')
c.JupyterHub.log_datefmt = '%Y-%m-%dT%H:%M:%S' # ISO8601 (expanded)
c.JupyterHub.template_paths = [
# custom HTML templates
str(files('cylc.uiserver') / 'templates')
]
# configure websocket pings (prevents clients / proxies closing seemingly idle
# connections and helps us to detect dead connections)
c.ServerApp.websocket_ping_interval = 5
c.ServerApp.websocket_ping_timeout = 5
# store JupyterHub runtime files in the user config directory
USER_CONF_ROOT.mkdir(parents=True, exist_ok=True)
c.JupyterHub.cookie_secret_file = f'{USER_CONF_ROOT / "cookie_secret"}'
c.JupyterHub.db_url = f'{USER_CONF_ROOT / "jupyterhub.sqlite"}'
c.ConfigurableHTTPProxy.pid_file = f'{USER_CONF_ROOT / "jupyterhub-proxy.pid"}'
# write Cylc logging to the user config directory
# NOTE: Parallel UIS instances will conflict over this file.
# See https://github.com/cylc/cylc-uiserver/issues/240
c.CylcUIServer.logging_config = {
'version': 1,
'handlers': {
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'level': 'INFO',
'filename': str(USER_CONF_ROOT / 'log' / 'log'),
'mode': 'a',
'backupCount': 5,
'maxBytes': 10485760,
'formatter': 'file_fmt',
},
},
'loggers': {
'CylcUIServer': {
'level': 'INFO',
'handlers': ['console', 'file'],
},
'cylc': {
'level': 'INFO',
'handlers': ['console', 'file'],
},
},
'formatters': {
'file_fmt': {
'format': '%(asctime)s %(levelname)-8s %(message)s',
'datefmt': '%Y-%m-%dT%H:%M:%S',
}
},
}
# Define the authorization-policy for Jupyter Server.
# This prevents users being granted full access to extensions such as Jupyter
# Lab as a result of being granted the ``access:servers`` permission in Jupyter
# Hub.
c.ServerApp.authorizer_class = CylcAuthorizer