Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't shim notebook if notebook<7 is available #123

Merged
merged 1 commit into from
Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions nbclassic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from notebook._version import __version__ as notebook_version
except Exception as e:
# No notebook python package found.
# Shimming notebook to jupyter_server for notebook extensions backwards compatiblity.
# Shimming notebook to jupyter_server for notebook extensions backwards compatibility.
# We shim the complete notebook module.
import jupyter_server
sys.modules["notebook"] = jupyter_server
Expand All @@ -25,25 +25,16 @@
if "notebook_version" in locals():
# Notebook is available on the platform.
# We shim based on the notebook version.
if notebook_version < "7":
from .shim_notebook import shim_notebook_6
# Shimming existing notebook python package < 7 to jupyter_server.
# For notebook extensions backwards compatiblity.
shim_notebook_6()
else:
from .shim_notebook import shim_notebook_7_and_above
# Shimming existing notebook python package >= 7 to jupyter_server.
# For notebook extensions backwards compatiblity.
shim_notebook_7_and_above()


# 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"
if not notebook_version < "7":
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
Expand Down
12 changes: 1 addition & 11 deletions nbclassic/shim_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys


def shim_notebook_6():
def shim_notebook():
"""Define in sys.module the needed notebook packages that should be fullfilled by
their corresponding and backwards-compatible jupyter-server packages.

Expand Down Expand Up @@ -84,13 +84,3 @@ def shim_notebook_6():

base.handlers.IPythonHandler = base.handlers.JupyterHandler
sys.modules["notebook.base.handlers.IPythonHandler"] = base.handlers.JupyterHandler


def shim_notebook_7_and_above():
"""For now, notebook v7 should be shimmed for now the same way
as notebook v6. This distinction could be useful for later
notebook >=7 evolutions.

TODO Discuss and remove if not needed.
"""
shim_notebook_6()