Skip to content

Commit

Permalink
Only apply the singleuser hub modifications if needed (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored Jul 26, 2024
1 parent 12e9761 commit 87b04de
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions jupyterlab_gallery/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def make_singleuser_app(cls):
return cls


# if jupyterhub is installed, apply jupyterhub patches
ServerAppClass = make_singleuser_app(ServerApp)
class classproperty(property):
def __get__(self, owner_self, owner_cls):
return self.fget(owner_cls)


class GalleryApp(ExtensionApp):
Expand Down Expand Up @@ -41,7 +42,18 @@ def initialize_handlers(self):

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

serverapp_class = ServerAppClass
@classproperty
def serverapp_class(cls):
"""If jupyterhub is installed, apply the jupyterhub patches,
but only do this when this property is accessed, which is when
the gallery is used as a standalone app.
"""
if cls._server_cls is None:
cls._server_cls = make_singleuser_app(ServerApp)
return cls._server_cls

_server_cls = None

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

0 comments on commit 87b04de

Please sign in to comment.