Skip to content

Commit ab19ce1

Browse files
authored
Merge pull request #123 from datalayer-externals/fix/shim-notebook-6
Don't shim notebook if notebook<7 is available
2 parents c1a0de3 + 94445af commit ab19ce1

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

nbclassic/__init__.py

+11-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from notebook._version import __version__ as notebook_version
1414
except Exception as e:
1515
# No notebook python package found.
16-
# Shimming notebook to jupyter_server for notebook extensions backwards compatiblity.
16+
# Shimming notebook to jupyter_server for notebook extensions backwards compatibility.
1717
# We shim the complete notebook module.
1818
import jupyter_server
1919
sys.modules["notebook"] = jupyter_server
@@ -25,25 +25,16 @@
2525
if "notebook_version" in locals():
2626
# Notebook is available on the platform.
2727
# We shim based on the notebook version.
28-
if notebook_version < "7":
29-
from .shim_notebook import shim_notebook_6
30-
# Shimming existing notebook python package < 7 to jupyter_server.
31-
# For notebook extensions backwards compatiblity.
32-
shim_notebook_6()
33-
else:
34-
from .shim_notebook import shim_notebook_7_and_above
35-
# Shimming existing notebook python package >= 7 to jupyter_server.
36-
# For notebook extensions backwards compatiblity.
37-
shim_notebook_7_and_above()
38-
39-
40-
# Sanity check for the notebook shim.
41-
42-
from jupyter_server.base.handlers import IPythonHandler as JupyterServerIPythonHandler
43-
assert JupyterServerIPythonHandler.__name__ == "JupyterHandler"
44-
45-
from notebook.base.handlers import IPythonHandler as NotebookIPythonHandler
46-
assert NotebookIPythonHandler.__name__ == "JupyterHandler" or NotebookIPythonHandler.__name__ == "IPythonHandler"
28+
if not notebook_version < "7":
29+
from .shim_notebook import shim_notebook
30+
# Shimming existing notebook python package > 6 to jupyter_server.
31+
# For notebook extensions backwards compatibility.
32+
shim_notebook()
33+
# Sanity check for the notebook shim.
34+
from jupyter_server.base.handlers import IPythonHandler as JupyterServerIPythonHandler
35+
assert JupyterServerIPythonHandler.__name__ == "JupyterHandler"
36+
from notebook.base.handlers import IPythonHandler as NotebookIPythonHandler
37+
assert NotebookIPythonHandler.__name__ == "JupyterHandler" or NotebookIPythonHandler.__name__ == "IPythonHandler"
4738

4839

4940
# Include both nbclassic/ and nbclassic/templates/. This makes it

nbclassic/shim_notebook.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88

99

10-
def shim_notebook_6():
10+
def shim_notebook():
1111
"""Define in sys.module the needed notebook packages that should be fullfilled by
1212
their corresponding and backwards-compatible jupyter-server packages.
1313
@@ -84,13 +84,3 @@ def shim_notebook_6():
8484

8585
base.handlers.IPythonHandler = base.handlers.JupyterHandler
8686
sys.modules["notebook.base.handlers.IPythonHandler"] = base.handlers.JupyterHandler
87-
88-
89-
def shim_notebook_7_and_above():
90-
"""For now, notebook v7 should be shimmed for now the same way
91-
as notebook v6. This distinction could be useful for later
92-
notebook >=7 evolutions.
93-
94-
TODO Discuss and remove if not needed.
95-
"""
96-
shim_notebook_6()

0 commit comments

Comments
 (0)