mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-16 06:22:59 +00:00
Support Jupyverse as a single-user server
This commit is contained in:
@@ -28,15 +28,20 @@ if not _extension_env:
|
|||||||
# - extension, if jupyter server 2
|
# - extension, if jupyter server 2
|
||||||
# - older subclass app, otherwise
|
# - older subclass app, otherwise
|
||||||
try:
|
try:
|
||||||
import jupyter_server
|
import jupyverse_api # noqa: F401
|
||||||
|
|
||||||
_server_major = int(jupyter_server.__version__.split(".", 1)[0])
|
|
||||||
except Exception:
|
|
||||||
# don't have jupyter-server, assume classic notebook
|
|
||||||
_as_extension = False
|
_as_extension = False
|
||||||
else:
|
except Exception:
|
||||||
# default to extension if jupyter-server >=2
|
try:
|
||||||
_as_extension = _server_major >= 2
|
import jupyter_server
|
||||||
|
|
||||||
|
_server_major = int(jupyter_server.__version__.split(".", 1)[0])
|
||||||
|
except Exception:
|
||||||
|
# don't have jupyter-server, assume classic notebook
|
||||||
|
_as_extension = False
|
||||||
|
else:
|
||||||
|
# default to extension if jupyter-server >=2
|
||||||
|
_as_extension = _server_major >= 2
|
||||||
|
|
||||||
elif _app_env == "extension":
|
elif _app_env == "extension":
|
||||||
_as_extension = True
|
_as_extension = True
|
||||||
@@ -67,9 +72,11 @@ else:
|
|||||||
from .app import SingleUserNotebookApp, main
|
from .app import SingleUserNotebookApp, main
|
||||||
|
|
||||||
# backward-compatibility
|
# backward-compatibility
|
||||||
JupyterHubLoginHandler = SingleUserNotebookApp.login_handler_class
|
if SingleUserNotebookApp is not None:
|
||||||
JupyterHubLogoutHandler = SingleUserNotebookApp.logout_handler_class
|
# not Jupyverse
|
||||||
OAuthCallbackHandler = SingleUserNotebookApp.oauth_callback_handler_class
|
JupyterHubLoginHandler = SingleUserNotebookApp.login_handler_class
|
||||||
|
JupyterHubLogoutHandler = SingleUserNotebookApp.logout_handler_class
|
||||||
|
OAuthCallbackHandler = SingleUserNotebookApp.oauth_callback_handler_class
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
Use JUPYTERHUB_SINGLEUSER_APP='notebook' for the legacy 'classic' notebook server (requires notebook<7).
|
Use JUPYTERHUB_SINGLEUSER_APP='notebook' for the legacy 'classic' notebook server (requires notebook<7).
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from traitlets import import_item
|
from traitlets import import_item
|
||||||
|
|
||||||
@@ -27,6 +28,7 @@ JUPYTERHUB_SINGLEUSER_APP = _app_shortcuts.get(
|
|||||||
JUPYTERHUB_SINGLEUSER_APP.replace("_", "-"), JUPYTERHUB_SINGLEUSER_APP
|
JUPYTERHUB_SINGLEUSER_APP.replace("_", "-"), JUPYTERHUB_SINGLEUSER_APP
|
||||||
)
|
)
|
||||||
|
|
||||||
|
jupyverse = None
|
||||||
|
|
||||||
if JUPYTERHUB_SINGLEUSER_APP:
|
if JUPYTERHUB_SINGLEUSER_APP:
|
||||||
if JUPYTERHUB_SINGLEUSER_APP in {"notebook", _app_shortcuts["notebook"]}:
|
if JUPYTERHUB_SINGLEUSER_APP in {"notebook", _app_shortcuts["notebook"]}:
|
||||||
@@ -48,25 +50,33 @@ if JUPYTERHUB_SINGLEUSER_APP:
|
|||||||
)
|
)
|
||||||
App = import_item(JUPYTERHUB_SINGLEUSER_APP)
|
App = import_item(JUPYTERHUB_SINGLEUSER_APP)
|
||||||
else:
|
else:
|
||||||
App = None
|
try:
|
||||||
_import_error = None
|
from jupyverse_api.cli import main as jupyverse
|
||||||
for JUPYTERHUB_SINGLEUSER_APP in (
|
|
||||||
"jupyter_server.serverapp.ServerApp",
|
App = None
|
||||||
"notebook.notebookapp.NotebookApp",
|
except Exception:
|
||||||
):
|
App = None
|
||||||
try:
|
_import_error = None
|
||||||
App = import_item(JUPYTERHUB_SINGLEUSER_APP)
|
for JUPYTERHUB_SINGLEUSER_APP in (
|
||||||
except ImportError as e:
|
"jupyter_server.serverapp.ServerApp",
|
||||||
if _import_error is None:
|
"notebook.notebookapp.NotebookApp",
|
||||||
_import_error = e
|
):
|
||||||
continue
|
try:
|
||||||
else:
|
App = import_item(JUPYTERHUB_SINGLEUSER_APP)
|
||||||
break
|
except ImportError as e:
|
||||||
if App is None:
|
if _import_error is None:
|
||||||
raise _import_error
|
_import_error = e
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
if App is None:
|
||||||
|
raise _import_error
|
||||||
|
|
||||||
|
|
||||||
SingleUserNotebookApp = make_singleuser_app(App)
|
if App is None:
|
||||||
|
SingleUserNotebookApp = None
|
||||||
|
else:
|
||||||
|
SingleUserNotebookApp = make_singleuser_app(App)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -77,6 +87,23 @@ def main():
|
|||||||
# This is a minimally extended ServerApp that does:
|
# This is a minimally extended ServerApp that does:
|
||||||
# 1. ensure lab extension is enabled, and
|
# 1. ensure lab extension is enabled, and
|
||||||
# 2. set default URL to `/lab`
|
# 2. set default URL to `/lab`
|
||||||
|
if jupyverse:
|
||||||
|
service_url = os.environ.get("JUPYTERHUB_SERVICE_URL")
|
||||||
|
url = urlparse(service_url)
|
||||||
|
try:
|
||||||
|
return jupyverse.callback(
|
||||||
|
open_browser=True,
|
||||||
|
host=url.hostname,
|
||||||
|
port=url.port,
|
||||||
|
set_=[
|
||||||
|
f"frontend.base_url={url.path}",
|
||||||
|
f"app.mount_path={url.path}",
|
||||||
|
],
|
||||||
|
disable=[],
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
return
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
_version_pat = re.compile(r"(\d+)\.(\d+)")
|
_version_pat = re.compile(r"(\d+)\.(\d+)")
|
||||||
|
Reference in New Issue
Block a user