-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from manics/jupyter-server
Depend on jupyter-server only, compatibility with jupyter server >= 2, notebook < 7
- Loading branch information
Showing
6 changed files
with
81 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
jupyter-packaging>=0.10 | ||
nbclassic | ||
notebook>=5.5,<7 | ||
packaging | ||
pytest | ||
pytest-cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Import base Handler classes from Jupyter Server or Notebook | ||
Must be called before importing .handlers to ensure the correct base classes | ||
""" | ||
import warnings | ||
|
||
_JupyterHandler = None | ||
|
||
|
||
def get_base_handler(app=None): | ||
"""Get the base JupyterHandler class to use | ||
Inferred from app class (either jupyter_server or notebook app) | ||
""" | ||
global _JupyterHandler | ||
if _JupyterHandler is not None: | ||
return _JupyterHandler | ||
if app is None: | ||
warnings.warn( | ||
"Guessing base JupyterHandler class. Specify an app to ensure the right JupyterHandler is used.", | ||
stacklevel=2, | ||
) | ||
from jupyter_server.base.handlers import JupyterHandler | ||
return JupyterHandler | ||
|
||
top_modules = {cls.__module__.split(".", 1)[0] for cls in app.__class__.mro()} | ||
if "jupyter_server" in top_modules: | ||
from jupyter_server.base.handlers import JupyterHandler | ||
|
||
_JupyterHandler = JupyterHandler | ||
return _JupyterHandler | ||
if "notebook" in top_modules: | ||
from notebook.base.handlers import IPythonHandler | ||
|
||
_JupyterHandler = IPythonHandler | ||
return _JupyterHandler | ||
|
||
warnings.warn(f"Failed to detect base JupyterHandler class for {app}.", stacklevel=2) | ||
from jupyter_server.base.handlers import JupyterHandler | ||
return JupyterHandler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters