Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 4, 2024
1 parent 4046444 commit 2a3d35b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 13 deletions.
6 changes: 1 addition & 5 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,7 @@ class ExtensionAppsHandler(JupyterHandler):
@allow_unauthenticated
def get(self) -> None:
self.set_header("Content-Type", "application/json")
self.finish(
json.dumps(
self.serverapp.extension_manager.extension_web_apps()
)
)
self.finish(json.dumps(self.serverapp.extension_manager.extension_web_apps()))


# -----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions jupyter_server/extension/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from __future__ import annotations

import importlib
from itertools import starmap
import re
from itertools import starmap

from tornado.gen import multi
from traitlets import Any, Bool, Dict, HasTraits, Instance, List, Unicode, default, observe
Expand All @@ -14,8 +14,7 @@
from .config import ExtensionConfigManager
from .utils import ExtensionMetadataError, ExtensionModuleNotFound, get_loader, get_metadata


RE_SLASH = x = re.compile('/+') # match any number of slashes
RE_SLASH = x = re.compile("/+") # match any number of slashes


class ExtensionPoint(HasTraits):
Expand Down Expand Up @@ -306,11 +305,12 @@ def extension_web_apps(self):
extensions which provide a default_url (i.e. a web application).
"""
return {
app.name: RE_SLASH.sub('/', f'{self.serverapp.base_url}/{app.default_url}')
app.name: RE_SLASH.sub("/", f"{self.serverapp.base_url}/{app.default_url}")
for extension_apps in self.serverapp.extension_manager.extension_apps.values()
# filter out extensions that do not provide a default_url OR
# set it to the root endpoint.
for app in extension_apps if getattr(app, 'default_url', '/') != '/'
for app in extension_apps
if getattr(app, "default_url", "/") != "/"
}

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/extension/mockextensions/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MockExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):
static_paths = [STATIC_PATH] # type:ignore[assignment]
mock_trait = Unicode("mock trait", config=True)
loaded = False
default_url = '/mockextension'
default_url = "/mockextension"

serverapp_config = {"jpserver_extensions": {"tests.extension.mockextensions.mock1": True}}

Expand Down
5 changes: 3 additions & 2 deletions tests/extension/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ async def test_extension_web_apps(jp_serverapp):

# there should be (at least) two extension applications
assert set(jp_serverapp.extension_manager.extension_apps) == {
'tests.extension.mockextensions', 'jupyter_server_terminals'
"tests.extension.mockextensions",
"jupyter_server_terminals",
}

# but only one extension web application
assert jp_serverapp.extension_manager.extension_web_apps == {
'mockextension': '/a%40b/mockextension'
"mockextension": "/a%40b/mockextension"
}

0 comments on commit 2a3d35b

Please sign in to comment.