Skip to content

Commit

Permalink
chore: datalayer config
Browse files Browse the repository at this point in the history
  • Loading branch information
echarles committed Mar 5, 2024
1 parent 5382d9a commit ff468fe
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
4 changes: 3 additions & 1 deletion datalayer/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
19 changes: 18 additions & 1 deletion datalayer/serverapplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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__})
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './jupyterlab';
49 changes: 46 additions & 3 deletions src/jupyterlab/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<DatalayerConfiguration, IDatalayerConfig | undefined>;
constructor() {
this._configurationChanged = new Signal<DatalayerConfiguration, IDatalayerConfig | undefined>(this);
}
set configuration(configuration: IDatalayerConfig | undefined) {
this._configuration = configuration;
this._configurationChanged.emit(configuration)
}
get configuration() {
return this._configuration;
}
get configurationChanged(): ISignal<DatalayerConfiguration, IDatalayerConfig | undefined> {
return this._configurationChanged;
}
}

export type IDatalayer = {
configuration: DatalayerConfiguration,
};

export const IDatalayer = new Token<IDatalayer>(
'@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';
Expand All @@ -20,11 +53,12 @@ let tracker: WidgetTracker<MainAreaWidget<DatalayerWidget>>;
/**
* Initialization data for the @datalayer/core extension.
*/
const plugin: JupyterFrontEndPlugin<void> = {
const plugin: JupyterFrontEndPlugin<IDatalayer> = {
id: '@datalayer/core:plugin',
autoStart: true,
requires: [ICommandPalette],
optional: [ISettingRegistry, ILauncher, ILayoutRestorer],
provides: IDatalayer,
deactivate: (
app: JupyterFrontEnd,
palette: ICommandPalette,
Expand All @@ -41,7 +75,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
settingRegistry?: ISettingRegistry,
launcher?: ILauncher,
restorer?: ILayoutRestorer,
) => {
): IDatalayer => {
const { commands } = app;
const command = CommandIDs.create;
if (!tracker) {
Expand Down Expand Up @@ -92,9 +126,17 @@ const plugin: JupyterFrontEndPlugin<void> = {
console.error(`Failed to load settings for ${plugin.id}`, reason);
});
}
const datalayer: IDatalayer = {
configuration: new DatalayerConfiguration(),
}
requestAPI<any>('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(
Expand All @@ -103,6 +145,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
}
);
console.log(`JupyterLab plugin ${plugin.id} is activated.`);
return datalayer;
}
};

Expand Down

0 comments on commit ff468fe

Please sign in to comment.