1"""Shim the notebook module for the classic extensions.
2"""
3
4# Copyright (c) Jupyter Development Team.
5# Distributed under the terms of the Modified BSD License.
6
7import sys
8
9
10def shim_notebook():
11 """Define in sys.module the needed notebook packages that should be fullfilled by
12 their corresponding and backwards-compatible jupyter-server packages.
13
14 TODO Can we lazy load these loadings?
15
16 Note: We could a custom module loader to achieve similar functionality. The
17 logic thar conditional loading seems to be more complicated than simply
18 listing by hand the needed subpackages but could avoid latency on server start.
19
20 https://docs.python.org/3/library/importlib.html#importlib.abc.Loader
21
22 These are the notebook packages we need to shim:
23
24 auth
25 base
26 bundler <- no, already available in nbclassic
27 edit <- no, already available in nbclassic
28 files
29 gateway
30 i18n <- no, already available in nbclassic
31 kernelspecs
32 nbconvert
33 notebook <- no, already available in nbclassic
34 prometheus
35 services
36 static <- no, already available in nbclassic
37 templates <- no, already available in nbclassic
38 terminal <- no, already available in nbclassic
39 tests <- no, already available in nbclassic
40 tree <- no, already available in nbclassic
41 view
42 __init__.py <- no, already available in nbclassic
43 __main__.py <- no, already available in nbclassic
44 _sysinfo.py <- no, already available in nbclassic
45 _tz.py
46 _version.py <- no, already available in nbclassic
47 config_manager.py <- no, already available in nbclassic
48 extensions.py <- no, already available in nbclassic
49 jstest.py <- no, already available in nbclassic
50 log.py
51 nbextensions.py <- no, already available in nbclassic
52 notebookapp.py <- no, already available in nbclassic
53 serverextensions.py <- no, already available in nbclassic
54 traittypes.py <- no, already available in nbclassic
55 transutils.py <- no, already available in nbclassic
56 utils.py
57
58 """
59
60 from jupyter_server import auth
61 sys.modules["notebook.auth"] = auth
62 from jupyter_server import base
63 sys.modules["notebook.base"] = base
64 from jupyter_server import files
65 sys.modules["notebook.files"] = files
66 from jupyter_server import gateway
67 sys.modules["notebook.gateway"] = gateway
68 from jupyter_server import kernelspecs
69 sys.modules["notebook.kernelspecs"] = kernelspecs
70 from jupyter_server import nbconvert
71 sys.modules["notebook.nbconvert"] = nbconvert
72 from jupyter_server import prometheus
73 sys.modules["notebook.prometheus"] = prometheus
74 from jupyter_server import services
75 sys.modules["notebook.services"] = services
76 from jupyter_server import view
77 sys.modules["notebook.view"] = view
78 from jupyter_server import _tz
79 sys.modules["notebook._tz"] = _tz
80 from jupyter_server import log
81 sys.modules["notebook.log"] = log
82 from jupyter_server import utils
83 sys.modules["notebook.utils"] = utils
84
85 from jupyter_server.base import handlers
86 base.handlers.IPythonHandler = handlers.JupyterHandler
87 sys.modules["notebook.base.handlers.IPythonHandler"] = base.handlers.JupyterHandler