From f6fb227a104538505c2abed8797b10123d82a386 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:09:59 +0100 Subject: [PATCH 1/2] When running on JupyterHub, apply the JupyterHub patches --- jupyterlab_gallery/app.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/jupyterlab_gallery/app.py b/jupyterlab_gallery/app.py index 7833bcd..c1a0387 100644 --- a/jupyterlab_gallery/app.py +++ b/jupyterlab_gallery/app.py @@ -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" @@ -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 @@ -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 From dc689d195c329ba0edb24d4ad66427ca3ed83254 Mon Sep 17 00:00:00 2001 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: Fri, 26 Jul 2024 13:12:58 +0100 Subject: [PATCH 2/2] Add documentation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8c0e87e..3030033 100644 --- a/README.md +++ b/README.md @@ -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