forked from jupyter/nbclassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
87 lines (69 loc) · 2.98 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
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
import os
import sys
from ._version import __version__
print("""
_ _
| \ | | _____ _____
| \| |/ _ \ \ /\ / / __|
| |\ | __/\ V V /\__ \\
|_| \_|\___| \_/\_/ |___/
If you plan to upgrade to Notebook 7, read https://nbclassic.readthedocs.io/en/latest/nbclassic_to_notebook7.html
Notebook 6 / NbClassic extensions will not work on Notebook 7.
""")
# Packagers: modify this line if you store the notebook static files elsewhere
DEFAULT_STATIC_FILES_PATH = os.path.join(os.path.dirname(__file__), "static")
NOTEBOOK_V7_DETECTED = False
# Notebook shim to ensure notebook extensions backwards compatiblity.
try:
from notebook._version import version_info as notebook_version_info
except Exception:
notebook_version_info = None
# No notebook python package found.
# Shimming notebook to jupyter_server for notebook extensions backwards compatibility.
# We shim the complete notebook module.
import jupyter_server
sys.modules["notebook"] = jupyter_server
from jupyter_server.base import handlers
from notebook.base import handlers as notebook_handlers
handlers.IPythonHandler = handlers.JupyterHandler
notebook_handlers.IPythonHandler = handlers.JupyterHandler
if notebook_version_info is not None:
# Notebook is available on the platform.
# We shim based on the notebook version.
if notebook_version_info >= (7,):
NOTEBOOK_V7_DETECTED = True
from .shim_notebook import shim_notebook
# Shimming existing notebook python package > 6 to jupyter_server.
# For notebook extensions backwards compatibility.
shim_notebook()
# Sanity check for the notebook shim.
from jupyter_server.base.handlers import IPythonHandler as JupyterServerIPythonHandler
assert JupyterServerIPythonHandler.__name__ == "JupyterHandler"
from notebook.base.handlers import IPythonHandler as NotebookIPythonHandler
assert NotebookIPythonHandler.__name__ == "JupyterHandler" or NotebookIPythonHandler.__name__ == "IPythonHandler"
# Include both nbclassic/ and nbclassic/templates/. This makes it
# possible for users to override a template with a file that inherits from that
# template.
#
# For example, if you want to override a specific block of notebook.html, you
# can create a file called notebook.html that inherits from
# templates/notebook.html, and the latter will resolve correctly to the base
# implementation.
DEFAULT_TEMPLATE_PATH_LIST = [
os.path.dirname(__file__),
os.path.join(os.path.dirname(__file__), "templates"),
]
def nbclassic_path():
if NOTEBOOK_V7_DETECTED:
return "/nbclassic"
return ""
def _jupyter_server_extension_paths():
# Locally import to avoid install errors.
from .notebookapp import NotebookApp
return [
{
'module': 'nbclassic.notebookapp',
'app': NotebookApp,
'name': 'jupyter-nbclassic'
}
]