Skip to content

Commit

Permalink
Adopt to run as a standalone app (#38)
Browse files Browse the repository at this point in the history
* Adopt to run as a standalone app

* Bump to v0.6.0
  • Loading branch information
krassowski authored Jul 26, 2024
1 parent e32cb50 commit 652b56c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions jupyterlab_gallery/app.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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")
Expand All @@ -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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ test = [
]
dev = ["ruff==0.4.4"]

[project.scripts]
jupyterlab-gallery = "jupyterlab_gallery:GalleryApp.launch_instance"

[tool.hatch.version]
source = "nodejs"

Expand Down

0 comments on commit 652b56c

Please sign in to comment.