From 652b56cab241ad2236ae8c66840d9151f8a28384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Krassowski?= <5832902+krassowski@users.noreply.github.com> Date: Fri, 26 Jul 2024 12:55:20 +0100 Subject: [PATCH] Adopt to run as a standalone app (#38) * Adopt to run as a standalone app * Bump to v0.6.0 --- README.md | 6 ++++++ jupyterlab_gallery/app.py | 19 ++++++++++++++++--- package.json | 2 +- pyproject.toml | 3 +++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 97573a3..8c0e87e 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,12 @@ c.GalleryManager.exhibits = [ Using the Python file enables injecting the personal access token (PAT) into the `token` stanza if you prefer to store it in an environment variable rather than in the configuration file (recommended). +The gallery application backend can be run as a standalone server app by executing: + +```bash +jupyterlab-gallery +``` + ## Requirements - JupyterLab >= 4.0.0 diff --git a/jupyterlab_gallery/app.py b/jupyterlab_gallery/app.py index 9610d9d..7833bcd 100644 --- a/jupyterlab_gallery/app.py +++ b/jupyterlab_gallery/app.py @@ -1,4 +1,5 @@ from jupyter_server.extension.application import ExtensionApp +from jupyter_server.serverapp import ServerApp from .handlers import ExhibitsHandler, GalleryHandler, PullHandler from .manager import GalleryManager @@ -12,9 +13,8 @@ class GalleryApp(ExtensionApp): ("jupyterlab-gallery/pull", PullHandler), ] - # default_url = "/jupyterlab-gallery" - # load_other_extensions = True - # file_url_prefix = "/gallery" + default_url = "/jupyterlab-gallery/gallery" + load_other_extensions = False def initialize_settings(self): self.log.info("Configured gallery manager") @@ -28,3 +28,16 @@ def initialize_handlers(self): self.serverapp.web_app.settings["nbapp"] = self.serverapp self.log.info(f"Registered {self.name} server extension") + + @classmethod + def make_serverapp(cls, **kwargs) -> ServerApp: + """Instantiate the ServerApp + + Override to disable default_services which would give access + to files on the disk (`contents` service) or allow execution + code (`kernels` service). + """ + server_app = super().make_serverapp(**kwargs) + assert len(server_app.default_services) > 1 + server_app.default_services = ("auth", "security") + return server_app diff --git a/package.json b/package.json index 622e97c..3f9ed87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jupyterlab-gallery", - "version": "0.5.0", + "version": "0.6.0", "description": "A JupyterLab gallery extension for presenting and downloading examples from remote repositories", "keywords": [ "jupyter", diff --git a/pyproject.toml b/pyproject.toml index 22475c7..d6b180e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,6 +39,9 @@ test = [ ] dev = ["ruff==0.4.4"] +[project.scripts] +jupyterlab-gallery = "jupyterlab_gallery:GalleryApp.launch_instance" + [tool.hatch.version] source = "nodejs"