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

Adopt the JupyterHub modifications when running in JupyterHub pod #41

Merged
merged 2 commits into from
Jul 26, 2024
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The gallery application backend can be run as a standalone server app by executi
jupyterlab-gallery
```

When run in JupyterHub context (with `jupyterhub` package installed), the standalone app will adopt the JupyterHub modifications to the single-user server.

## Requirements

- JupyterLab >= 4.0.0
Expand Down
15 changes: 15 additions & 0 deletions jupyterlab_gallery/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
from .manager import GalleryManager


try:
from jupyterhub.singleuser.mixins import make_singleuser_app
except ImportError:

def make_singleuser_app(cls):
return cls


# if jupyterhub is installed, apply jupyterhub patches
ServerAppClass = make_singleuser_app(ServerApp)


class GalleryApp(ExtensionApp):
name = "gallery"

Expand All @@ -29,6 +41,8 @@ def initialize_handlers(self):

self.log.info(f"Registered {self.name} server extension")

serverapp_class = ServerAppClass

@classmethod
def make_serverapp(cls, **kwargs) -> ServerApp:
"""Instantiate the ServerApp
Expand All @@ -38,6 +52,7 @@ def make_serverapp(cls, **kwargs) -> ServerApp:
code (`kernels` service).
"""
server_app = super().make_serverapp(**kwargs)
assert isinstance(server_app, ServerAppClass)
assert len(server_app.default_services) > 1
server_app.default_services = ("auth", "security")
return server_app
Loading