-
Notifications
You must be signed in to change notification settings - Fork 147
/
__init__.py
53 lines (43 loc) · 1.82 KB
/
__init__.py
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
from .handlers import setup_handlers
from .config import ServerProxy as ServerProxyConfig, make_handlers, get_entrypoint_server_processes, make_server_process
from jupyter_server.utils import url_path_join as ujoin
from .api import ServersInfoHandler, IconHandler
# Jupyter Extension points
def _jupyter_server_extension_points():
return [{
'module': 'jupyter_server_proxy',
}]
def _jupyter_nbextension_paths():
return [{
"section": "tree",
"dest": "jupyter_server_proxy",
'src': 'static',
"require": "jupyter_server_proxy/tree"
}]
def _load_jupyter_server_extension(nbapp):
# Set up handlers picked up via config
base_url = nbapp.web_app.settings['base_url']
serverproxy_config = ServerProxyConfig(parent=nbapp)
server_processes = [
make_server_process(name, server_process_config, serverproxy_config)
for name, server_process_config in serverproxy_config.servers.items()
]
server_processes += get_entrypoint_server_processes(serverproxy_config)
server_handlers = make_handlers(base_url, server_processes)
nbapp.web_app.add_handlers('.*', server_handlers)
# Set up default non-server handler
setup_handlers(
nbapp.web_app,
serverproxy_config,
)
icons = {}
for sp in server_processes:
if sp.launcher_entry.enabled and sp.launcher_entry.icon_path:
icons[sp.name] = sp.launcher_entry.icon_path
nbapp.web_app.add_handlers('.*', [
(ujoin(base_url, 'server-proxy/servers-info'), ServersInfoHandler, {'server_processes': server_processes}),
(ujoin(base_url, 'server-proxy/icon/(.*)'), IconHandler, {'icons': icons}),
])
# For backward compatibility
load_jupyter_server_extension = _load_jupyter_server_extension
_jupyter_server_extension_paths = _jupyter_server_extension_points