Skip to content

Commit

Permalink
Load overrides once, rather than in each settings handler
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed May 22, 2024
1 parent 1e0367f commit 1ea2d53
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
9 changes: 9 additions & 0 deletions jupyterlab_server/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .licenses_handler import LicensesHandler, LicensesManager
from .listings_handler import ListingsHandler, fetch_listings
from .settings_handler import SettingsHandler
from .settings_utils import _get_overrides
from .themes_handler import ThemesHandler
from .translations_handler import TranslationsHandler
from .workspaces_handler import WorkspacesHandler, WorkspacesManager
Expand Down Expand Up @@ -227,11 +228,19 @@ def add_handlers(handlers: list[Any], extension_app: LabServerApp) -> None:

# Handle local settings.
if extension_app.schemas_dir:
# Load overrides once, rather than in each copy of the settings handler
overrides, error = _get_overrides(extension_app.app_settings_dir)

if error:
overrides_warning = "Failed loading overrides: %s"
extension_app.log.warning(overrides_warning, error)

settings_config: dict[str, Any] = {
"app_settings_dir": extension_app.app_settings_dir,
"schemas_dir": extension_app.schemas_dir,
"settings_dir": extension_app.user_settings_dir,
"labextensions_path": labextensions_path,
"overrides": overrides,
}

# Handle requests for the list of settings. Make slash optional.
Expand Down
3 changes: 2 additions & 1 deletion jupyterlab_server/settings_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ def initialize( # type:ignore[override]
schemas_dir: str,
settings_dir: str,
labextensions_path: list[str],
overrides: dict[str, Any],
**kwargs: Any, # noqa: ARG002
) -> None:
"""Initialize the handler."""
SchemaHandler.initialize(
self, app_settings_dir, schemas_dir, settings_dir, labextensions_path
self, app_settings_dir, schemas_dir, settings_dir, labextensions_path, overrides
)
ExtensionHandlerMixin.initialize(self, name)

Expand Down
7 changes: 2 additions & 5 deletions jupyterlab_server/settings_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,20 +448,17 @@ def initialize(
schemas_dir: str,
settings_dir: str,
labextensions_path: list[str] | None,
overrides: dict[str, Any],
**kwargs: Any,
) -> None:
"""Initialize the handler."""
super().initialize(**kwargs)
self.overrides, error = _get_overrides(app_settings_dir)
self.overrides = overrides
self.app_settings_dir = app_settings_dir
self.schemas_dir = schemas_dir
self.settings_dir = settings_dir
self.labextensions_path = labextensions_path

if error:
overrides_warning = "Failed loading overrides: %s"
self.log.warning(overrides_warning, error)

def get_current_locale(self) -> str:
"""
Get the current locale as specified in the translation-extension settings.
Expand Down

0 comments on commit 1ea2d53

Please sign in to comment.