Skip to content

Commit

Permalink
Use plugins from voila
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Nov 8, 2022
1 parent db68eed commit 0e75bed
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 263 deletions.
189 changes: 0 additions & 189 deletions packages/voila/index.js

This file was deleted.

5 changes: 1 addition & 4 deletions packages/voila/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ export * from './app';
export * from './manager';
export * from './shell';
export * from './output';

import * as plugins from './plugins';

export { plugins };
export * from './plugins';
4 changes: 2 additions & 2 deletions packages/voila/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { PageConfig, URLExt } from '@jupyterlab/coreutils';

import { VoilaApp } from './app';
import { VoilaShell } from './shell';
import plugins from './plugins';

function loadScript(url: string): Promise<any> {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -68,9 +69,8 @@ async function main() {
// This would also need the theme manager plugin and settings
// require('@jupyterlab/theme-light-extension'),
// require('@jupyterlab/theme-dark-extension'),
require('./plugins')
plugins
];

const mimeExtensions = [require('@jupyterlab/json-extension')];

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/voila/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { WidgetManager as VoilaWidgetManager } from './manager';
/**
* The default paths.
*/
const paths: JupyterFrontEndPlugin<JupyterFrontEnd.IPaths> = {
export const pathsPlugin: JupyterFrontEndPlugin<JupyterFrontEnd.IPaths> = {
id: '@voila-dashboards/voila:paths',
activate: (
app: JupyterFrontEnd<JupyterFrontEnd.IShell>
Expand All @@ -51,7 +51,7 @@ const paths: JupyterFrontEndPlugin<JupyterFrontEnd.IPaths> = {
* TODO: a cleaner solution would involve a custom ServiceManager to the VoilaApp
* to prevent the default behavior of polling the /api endpoints.
*/
const stopPolling: JupyterFrontEndPlugin<void> = {
export const stopPollingPlugin: JupyterFrontEndPlugin<void> = {
id: '@voila-dashboards/voila:stop-polling',
autoStart: true,
activate: (app: JupyterFrontEnd): void => {
Expand All @@ -69,7 +69,7 @@ const stopPolling: JupyterFrontEndPlugin<void> = {
/**
* A simplified Translator
*/
const translator: JupyterFrontEndPlugin<ITranslator> = {
export const translatorPlugin: JupyterFrontEndPlugin<ITranslator> = {
id: '@voila-dashboards/voila:translator',
activate: (app: JupyterFrontEnd<JupyterFrontEnd.IShell>): ITranslator => {
const translationManager = new TranslationManager();
Expand All @@ -82,7 +82,7 @@ const translator: JupyterFrontEndPlugin<ITranslator> = {
/**
* The Voila widgets manager plugin.
*/
const widgetManager: JupyterFrontEndPlugin<IJupyterWidgetRegistry> = {
export const widgetManager: JupyterFrontEndPlugin<IJupyterWidgetRegistry> = {
id: '@voila-dashboards/voila:widget-manager',
autoStart: true,
requires: [IRenderMimeRegistry],
Expand Down Expand Up @@ -135,9 +135,9 @@ const widgetManager: JupyterFrontEndPlugin<IJupyterWidgetRegistry> = {
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
paths,
stopPolling,
translator,
pathsPlugin,
stopPollingPlugin,
translatorPlugin,
widgetManager
];

Expand Down
4 changes: 1 addition & 3 deletions packages/voilite/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ interface ICellData {
cell_type: string;
cell_source: string;
}
declare var cells: {
[key: number]: ICellData;
};

declare function update_loading_text(
cell_index: number,
cell_count: number,
Expand Down
3 changes: 1 addition & 2 deletions packages/voilite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,14 @@ async function main() {
litePluginsToRegister.push(plugin);
}
});
console.log('start server');

// create the in-browser JupyterLite Server
const jupyterLiteServer = new JupyterLiteServer({ shell: null as never });

jupyterLiteServer.registerPluginModules(litePluginsToRegister);
// start the server
await jupyterLiteServer.start();
console.log('done server');

const serviceManager = jupyterLiteServer.serviceManager;
const app = new VoiliteApp({
serviceManager: serviceManager as any,
Expand Down
61 changes: 5 additions & 56 deletions packages/voilite/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PageConfig } from '@jupyterlab/coreutils';
/***************************************************************************
* Copyright (c) 2022, Voilà contributors *
* Copyright (c) 2022, QuantStack *
Expand All @@ -13,64 +12,15 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { IThemeManager } from '@jupyterlab/apputils';
import { ITranslator, TranslationManager } from '@jupyterlab/translation';
import { PromiseDelegate } from '@lumino/coreutils';
import { VoilaApp } from '@voila-dashboards/voila';

import { translatorPlugin, pathsPlugin } from '@voila-dashboards/voila';
import { PageConfig } from '@jupyterlab/coreutils';
import { VoiliteWidgetManager } from './manager';

/**
* The default paths.
*/
const paths: JupyterFrontEndPlugin<JupyterFrontEnd.IPaths> = {
id: '@voila-dashboards/voila:paths',
activate: (
app: JupyterFrontEnd<JupyterFrontEnd.IShell>
): JupyterFrontEnd.IPaths => {
return (app as VoilaApp).paths;
},
autoStart: true,
provides: JupyterFrontEnd.IPaths
};

/**
* A plugin to stop polling the kernels, sessions and kernel specs.
*
* TODO: a cleaner solution would involve a custom ServiceManager to the VoilaApp
* to prevent the default behavior of polling the /api endpoints.
*/
const stopPolling: JupyterFrontEndPlugin<void> = {
id: '@voila-dashboards/voila:stop-polling',
autoStart: true,
activate: (app: JupyterFrontEnd): void => {
app.serviceManager.sessions?.ready.then(value => {
app.serviceManager.sessions['_kernelManager']['_pollModels']?.stop();
void app.serviceManager.sessions['_pollModels'].stop();
});

app.serviceManager.kernelspecs?.ready.then(value => {
void app.serviceManager.kernelspecs.dispose();
});
}
};

/**
* A simplified Translator
*/
const translator: JupyterFrontEndPlugin<ITranslator> = {
id: '@voila-dashboards/voila:translator',
activate: (app: JupyterFrontEnd<JupyterFrontEnd.IShell>): ITranslator => {
const translationManager = new TranslationManager();
return translationManager;
},
autoStart: true,
provides: ITranslator
};

export const managerPromise = new PromiseDelegate<VoiliteWidgetManager>();

/**
* The Voila widgets manager plugin.
* The Voilite widgets manager plugin.
*/
const widgetManager = {
id: '@voila-dashboards/voilite:widget-manager',
Expand Down Expand Up @@ -113,9 +63,8 @@ const themePlugin: JupyterFrontEndPlugin<void> = {
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
paths,
stopPolling,
translator,
pathsPlugin,
translatorPlugin,
widgetManager,
themePlugin
];
Expand Down

0 comments on commit 0e75bed

Please sign in to comment.