Skip to content

Commit

Permalink
Add the plugin manager (#7198)
Browse files Browse the repository at this point in the history
* Add the pluginmanager

* iterate

* Parse info in app
  • Loading branch information
jtpio authored Dec 27, 2023
1 parent 0fbb1b2 commit 251e0e3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 4 deletions.
20 changes: 17 additions & 3 deletions app/index.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ async function loadComponent(url, scope) {
async function createModule(scope, module) {
try {
const factory = await window._JUPYTERLAB[scope].get(module);
return factory();
const instance = factory();
instance.__scope__ = scope;
return instance;
} catch (e) {
console.warn(
`Failed to create module: package: ${scope}; module: ${module}`
Expand Down Expand Up @@ -79,6 +81,7 @@ async function main() {

// populate the list of disabled extensions
const disabled = [];
const availablePlugins = [];

/**
* Iterate over active plugins in an extension.
Expand All @@ -98,7 +101,18 @@ async function main() {

let plugins = Array.isArray(exports) ? exports : [exports];
for (let plugin of plugins) {
if (PageConfig.Extension.isDisabled(plugin.id)) {
const isDisabled = PageConfig.Extension.isDisabled(plugin.id);
availablePlugins.push({
id: plugin.id,
description: plugin.description,
requires: plugin.requires ?? [],
optional: plugin.optional ?? [],
provides: plugin.provides ?? null,
autoStart: plugin.autoStart,
enabled: !isDisabled,
extension: extension.__scope__
});
if (isDisabled) {
disabled.push(plugin.id);
continue;
}
Expand Down Expand Up @@ -200,7 +214,7 @@ async function main() {
PageConfig.setOption('allPlugins', '{{{ json notebook_plugins }}}');

const NotebookApp = require('@jupyter-notebook/application').NotebookApp;
const app = new NotebookApp({ mimeExtensions });
const app = new NotebookApp({ mimeExtensions, availablePlugins });

app.registerPluginModules(mods);

Expand Down
2 changes: 2 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
"@jupyterlab/metadataform-extension": "^4.1.0-beta.0",
"@jupyterlab/notebook-extension": "^4.1.0-beta.0",
"@jupyterlab/pdf-extension": "^4.1.0-beta.0",
"@jupyterlab/pluginmanager-extension": "^4.1.0-beta.0",
"@jupyterlab/running-extension": "^4.1.0-beta.0",
"@jupyterlab/settingeditor": "^4.1.0-beta.0",
"@jupyterlab/settingeditor-extension": "^4.1.0-beta.0",
Expand Down Expand Up @@ -284,6 +285,7 @@
"@jupyterlab/notebook-extension:tracker",
"@jupyterlab/notebook-extension:widget-factory"
],
"@jupyterlab/pluginmanager-extension": true,
"@jupyterlab/shortcuts-extension": true,
"@jupyterlab/terminal-extension": true,
"@jupyterlab/theme-light-extension": true,
Expand Down
3 changes: 2 additions & 1 deletion packages/application-extension/schema/shell.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"title": "Customize shell widget positioning",
"description": "Overrides default widget position in the application layout",
"default": {
"Markdown Preview": { "area": "right" }
"Markdown Preview": { "area": "right" },
"Plugins": { "area": "left" }
}
}
},
Expand Down
25 changes: 25 additions & 0 deletions packages/application/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Distributed under the terms of the Modified BSD License.

import {
JupyterLab,
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
Expand Down Expand Up @@ -40,6 +41,17 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
}
}

// Create an IInfo dictionary from the options to override the defaults.
const info = Object.keys(JupyterLab.defaultInfo).reduce((acc, val) => {
if (val in options) {
(acc as any)[val] = JSON.parse(JSON.stringify((options as any)[val]));
}
return acc;
}, {} as Partial<JupyterLab.IInfo>);

// Populate application info.
this._info = { ...JupyterLab.defaultInfo, ...info };

this.restored = this.shell.restored;

this.restored.then(() => this._formatter.invoke());
Expand Down Expand Up @@ -71,6 +83,13 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {

readonly version = PageConfig.getOption('appVersion') ?? 'unknown';

/**
* The NotebookApp application information dictionary.
*/
get info(): JupyterLab.IInfo {
return this._info;
}

/**
* The JupyterLab application paths dictionary.
*/
Expand Down Expand Up @@ -149,6 +168,7 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
});
}

private _info: JupyterLab.IInfo = JupyterLab.defaultInfo;
private _formatter = new Throttler(() => {
Private.setFormat(this);
}, 250);
Expand All @@ -173,6 +193,11 @@ export namespace NotebookApp {
* The mime renderer extensions.
*/
readonly mimeExtensions: IRenderMime.IExtensionModule[];

/**
* The information about available plugins.
*/
readonly availablePlugins: JupyterLab.IPluginInfo[];
}

/**
Expand Down
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,7 @@ __metadata:
"@jupyterlab/metadataform-extension": ^4.1.0-beta.0
"@jupyterlab/notebook-extension": ^4.1.0-beta.0
"@jupyterlab/pdf-extension": ^4.1.0-beta.0
"@jupyterlab/pluginmanager-extension": ^4.1.0-beta.0
"@jupyterlab/running-extension": ^4.1.0-beta.0
"@jupyterlab/settingeditor": ^4.1.0-beta.0
"@jupyterlab/settingeditor-extension": ^4.1.0-beta.0
Expand Down Expand Up @@ -3898,6 +3899,20 @@ __metadata:
languageName: node
linkType: hard

"@jupyterlab/pluginmanager-extension@npm:^4.1.0-beta.0":
version: 4.1.0-beta.0
resolution: "@jupyterlab/pluginmanager-extension@npm:4.1.0-beta.0"
dependencies:
"@jupyterlab/application": ^4.1.0-beta.0
"@jupyterlab/apputils": ^4.2.0-beta.0
"@jupyterlab/pluginmanager": ^4.1.0-beta.0
"@jupyterlab/translation": ^4.1.0-beta.0
"@jupyterlab/ui-components": ^4.1.0-beta.0
"@lumino/coreutils": ^2.1.2
checksum: 70a2defa672b2e273d304846d5e7a0ca8f9b617787044fc65bc5332403f0d7d3f78ce9e2eee8d7b1d1085f806b084e2f12e3e1e6a9a83f0905e9a927982593e0
languageName: node
linkType: hard

"@jupyterlab/pluginmanager@npm:^4.1.0-beta.0":
version: 4.1.0-beta.0
resolution: "@jupyterlab/pluginmanager@npm:4.1.0-beta.0"
Expand Down

0 comments on commit 251e0e3

Please sign in to comment.