Skip to content

Commit

Permalink
Adopt the JupyterHub modifications when running in JupyterHub pod (#41)
Browse files Browse the repository at this point in the history
* When running on JupyterHub, apply the JupyterHub patches

* Add documentation
  • Loading branch information
krassowski authored Jul 26, 2024
1 parent 3454cfe commit 12e9761
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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

0 comments on commit 12e9761

Please sign in to comment.