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:
@@ -27,6 +27,11 @@ if not _extension_env:
|
||||
# default behavior:
|
||||
# - extension, if jupyter server 2
|
||||
# - older subclass app, otherwise
|
||||
try:
|
||||
import jupyverse_api # noqa: F401
|
||||
|
||||
_as_extension = False
|
||||
except Exception:
|
||||
try:
|
||||
import jupyter_server
|
||||
|
||||
@@ -67,6 +72,8 @@ else:
|
||||
from .app import SingleUserNotebookApp, main
|
||||
|
||||
# backward-compatibility
|
||||
if SingleUserNotebookApp is not None:
|
||||
# not Jupyverse
|
||||
JupyterHubLoginHandler = SingleUserNotebookApp.login_handler_class
|
||||
JupyterHubLogoutHandler = SingleUserNotebookApp.logout_handler_class
|
||||
OAuthCallbackHandler = SingleUserNotebookApp.oauth_callback_handler_class
|
||||
|
@@ -9,6 +9,7 @@
|
||||
Use JUPYTERHUB_SINGLEUSER_APP='notebook' for the legacy 'classic' notebook server (requires notebook<7).
|
||||
"""
|
||||
import os
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from traitlets import import_item
|
||||
|
||||
@@ -27,6 +28,7 @@ JUPYTERHUB_SINGLEUSER_APP = _app_shortcuts.get(
|
||||
JUPYTERHUB_SINGLEUSER_APP.replace("_", "-"), JUPYTERHUB_SINGLEUSER_APP
|
||||
)
|
||||
|
||||
jupyverse = None
|
||||
|
||||
if JUPYTERHUB_SINGLEUSER_APP:
|
||||
if JUPYTERHUB_SINGLEUSER_APP in {"notebook", _app_shortcuts["notebook"]}:
|
||||
@@ -48,6 +50,11 @@ if JUPYTERHUB_SINGLEUSER_APP:
|
||||
)
|
||||
App = import_item(JUPYTERHUB_SINGLEUSER_APP)
|
||||
else:
|
||||
try:
|
||||
from jupyverse_api.cli import main as jupyverse
|
||||
|
||||
App = None
|
||||
except Exception:
|
||||
App = None
|
||||
_import_error = None
|
||||
for JUPYTERHUB_SINGLEUSER_APP in (
|
||||
@@ -66,6 +73,9 @@ else:
|
||||
raise _import_error
|
||||
|
||||
|
||||
if App is None:
|
||||
SingleUserNotebookApp = None
|
||||
else:
|
||||
SingleUserNotebookApp = make_singleuser_app(App)
|
||||
|
||||
|
||||
@@ -77,6 +87,23 @@ def main():
|
||||
# This is a minimally extended ServerApp that does:
|
||||
# 1. ensure lab extension is enabled, and
|
||||
# 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
|
||||
|
||||
_version_pat = re.compile(r"(\d+)\.(\d+)")
|
||||
|
Reference in New Issue
Block a user