forked from jupyterlab/jupyterlab
/
labapp.py
99 lines (68 loc) · 2.76 KB
/
labapp.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
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
# coding: utf-8
"""A tornado based Jupyter lab server."""
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
from notebook.notebookapp import NotebookApp, flags
from jupyter_core.application import JupyterApp
from traitlets import Bool, Unicode
from ._version import __version__
from .extension import load_jupyter_server_extension
from .commands import build, clean, describe
class LabBuildApp(JupyterApp):
version = __version__
description = "Build the JupyterLab application"
def start(self):
build()
class LabCleanApp(JupyterApp):
version = __version__
description = "Clean the JupyterLab application"
def start(self):
clean()
class LabDescribeApp(JupyterApp):
version = __version__
description = "Git description the JupyterLab application"
def start(self):
print(describe())
lab_flags = dict(flags)
lab_flags['dev-mode'] = (
{'LabApp': {'dev_mode': True}},
"Start the app in dev mode."
)
class LabApp(NotebookApp):
version = __version__
description = """
JupyterLab - An extensible computational environment for Jupyter.
This launches a Tornado based HTML Server that serves up an
HTML5/Javascript JupyterLab client.
"""
examples = """
jupyter lab # start JupyterLab
jupyter lab --certfile=mycert.pem # use SSL/TLS certificate
"""
flags = lab_flags
subcommands = dict(
build=(LabBuildApp, LabBuildApp.description.splitlines()[0]),
clean=(LabCleanApp, LabCleanApp.description.splitlines()[0]),
describe=(LabDescribeApp, LabBuildApp.description.splitlines()[0])
)
default_url = Unicode('/lab', config=True,
help="The default URL to redirect to from `/`")
dev_mode = Bool(False, config=True,
help="Whether to start the app in dev mode")
def init_server_extensions(self):
"""Load any extensions specified by config.
Import the module, then call the load_jupyter_server_extension function,
if one exists.
If the JupyterLab server extension is not enabled, it will
be manually loaded with a warning.
The extension API is experimental, and may change in future releases.
"""
super(LabApp, self).init_server_extensions()
msg = 'JupyterLab server extension not enabled, manually loading...'
if not self.nbserver_extensions.get('jupyterlab', False):
self.log.warn(msg)
load_jupyter_server_extension(self)
#-----------------------------------------------------------------------------
# Main entry point
#-----------------------------------------------------------------------------
main = launch_new_instance = LabApp.launch_instance