From ff468fe9471a3d3cbe86951a2fe2998a44377335 Mon Sep 17 00:00:00 2001 From: echarles Date: Tue, 5 Mar 2024 19:07:37 +0100 Subject: [PATCH] chore: datalayer config --- datalayer/handlers.py | 4 ++- datalayer/serverapplication.py | 19 ++++++++++++- src/index.ts | 1 + src/jupyterlab/index.ts | 49 +++++++++++++++++++++++++++++++--- 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/datalayer/handlers.py b/datalayer/handlers.py index 8672ad8..7b1b686 100644 --- a/datalayer/handlers.py +++ b/datalayer/handlers.py @@ -29,9 +29,11 @@ class ConfigHandler(ExtensionHandlerMixin, APIHandler): @tornado.web.authenticated def get(self): - """Returns the configurations of the server extensions.""" + """Returns the configuration of the server extension.""" + settings = self.settings["datalayer_config"] res = json.dumps({ "extension": "datalayer", "version": __version__, + "settings": settings, }) self.finish(res) diff --git a/datalayer/serverapplication.py b/datalayer/serverapplication.py index 2c5e694..fe3a59b 100644 --- a/datalayer/serverapplication.py +++ b/datalayer/serverapplication.py @@ -2,6 +2,10 @@ import os +from traitlets import ( + Unicode, Bool, +) + from jupyter_server.utils import url_path_join from jupyter_server.extension.application import ExtensionApp, ExtensionAppJinjaMixin @@ -26,8 +30,21 @@ class DatalayerExtensionApp(ExtensionAppJinjaMixin, ExtensionApp): static_paths = [DEFAULT_STATIC_FILES_PATH] template_paths = [DEFAULT_TEMPLATE_FILES_PATH] + launcher_category = Unicode("Datalayer", + config=True, + help=("Category to use for the applicaton launcher."), + ) + kubernetes_hostname = Unicode("io.datalayer.run", + config=True, + help="""Kubernetes hostname to connect.""" + ) + def initialize_settings(self): - pass + settings = dict( + launcher_category=self.launcher_category, + kubernetes_hostname=self.kubernetes_hostname, + ) + self.settings.update(**settings) def initialize_templates(self): self.serverapp.jinja_template_vars.update({"datalayer_version": __version__}) diff --git a/src/index.ts b/src/index.ts index e69de29..f40f37a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -0,0 +1 @@ +export * from './jupyterlab'; diff --git a/src/jupyterlab/index.ts b/src/jupyterlab/index.ts index 91ca9ff..efc9301 100644 --- a/src/jupyterlab/index.ts +++ b/src/jupyterlab/index.ts @@ -1,3 +1,5 @@ +import { Token } from '@lumino/coreutils'; +import { ISignal, Signal } from '@lumino/signaling'; import { JupyterFrontEnd, JupyterFrontEndPlugin, ILayoutRestorer } from '@jupyterlab/application'; import { MainAreaWidget, ICommandPalette, WidgetTracker } from '@jupyterlab/apputils'; import { ISettingRegistry } from '@jupyterlab/settingregistry'; @@ -8,8 +10,39 @@ import { DatalayerWidget } from './widget'; import '../../style/index.css'; +export type IDatalayerConfig = { + category: string, + kubernetesHostname: string, +}; + +export class DatalayerConfiguration { + private _configuration?: IDatalayerConfig; + private _configurationChanged: Signal; + constructor() { + this._configurationChanged = new Signal(this); + } + set configuration(configuration: IDatalayerConfig | undefined) { + this._configuration = configuration; + this._configurationChanged.emit(configuration) + } + get configuration() { + return this._configuration; + } + get configurationChanged(): ISignal { + return this._configurationChanged; + } +} + +export type IDatalayer = { + configuration: DatalayerConfiguration, +}; + +export const IDatalayer = new Token( + '@datalayer/core:plugin' +); + /** - * The command IDs used by the plugin. + * The command IDs used by the plugin.k */ namespace CommandIDs { export const create = 'datalayer:create-datalayer-widget'; @@ -20,11 +53,12 @@ let tracker: WidgetTracker>; /** * Initialization data for the @datalayer/core extension. */ -const plugin: JupyterFrontEndPlugin = { +const plugin: JupyterFrontEndPlugin = { id: '@datalayer/core:plugin', autoStart: true, requires: [ICommandPalette], optional: [ISettingRegistry, ILauncher, ILayoutRestorer], + provides: IDatalayer, deactivate: ( app: JupyterFrontEnd, palette: ICommandPalette, @@ -41,7 +75,7 @@ const plugin: JupyterFrontEndPlugin = { settingRegistry?: ISettingRegistry, launcher?: ILauncher, restorer?: ILayoutRestorer, - ) => { + ): IDatalayer => { const { commands } = app; const command = CommandIDs.create; if (!tracker) { @@ -92,9 +126,17 @@ const plugin: JupyterFrontEndPlugin = { console.error(`Failed to load settings for ${plugin.id}`, reason); }); } + const datalayer: IDatalayer = { + configuration: new DatalayerConfiguration(), + } requestAPI('config') .then(data => { console.log('Received config', data); + const configuration = { + category: data.settings.launcher_category, + kubernetesHostname: data.settings.kubernetes_hostname, + } + datalayer.configuration.configuration = configuration; }) .catch(reason => { console.error( @@ -103,6 +145,7 @@ const plugin: JupyterFrontEndPlugin = { } ); console.log(`JupyterLab plugin ${plugin.id} is activated.`); + return datalayer; } };