Skip to content

Commit 251e0e3

Browse files
authored
Add the plugin manager (#7198)
* Add the pluginmanager * iterate * Parse info in app
1 parent 0fbb1b2 commit 251e0e3

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

app/index.template.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ async function loadComponent(url, scope) {
3333
async function createModule(scope, module) {
3434
try {
3535
const factory = await window._JUPYTERLAB[scope].get(module);
36-
return factory();
36+
const instance = factory();
37+
instance.__scope__ = scope;
38+
return instance;
3739
} catch (e) {
3840
console.warn(
3941
`Failed to create module: package: ${scope}; module: ${module}`
@@ -79,6 +81,7 @@ async function main() {
7981

8082
// populate the list of disabled extensions
8183
const disabled = [];
84+
const availablePlugins = [];
8285

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

99102
let plugins = Array.isArray(exports) ? exports : [exports];
100103
for (let plugin of plugins) {
101-
if (PageConfig.Extension.isDisabled(plugin.id)) {
104+
const isDisabled = PageConfig.Extension.isDisabled(plugin.id);
105+
availablePlugins.push({
106+
id: plugin.id,
107+
description: plugin.description,
108+
requires: plugin.requires ?? [],
109+
optional: plugin.optional ?? [],
110+
provides: plugin.provides ?? null,
111+
autoStart: plugin.autoStart,
112+
enabled: !isDisabled,
113+
extension: extension.__scope__
114+
});
115+
if (isDisabled) {
102116
disabled.push(plugin.id);
103117
continue;
104118
}
@@ -200,7 +214,7 @@ async function main() {
200214
PageConfig.setOption('allPlugins', '{{{ json notebook_plugins }}}');
201215

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

205219
app.registerPluginModules(mods);
206220

app/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"@jupyterlab/metadataform-extension": "^4.1.0-beta.0",
164164
"@jupyterlab/notebook-extension": "^4.1.0-beta.0",
165165
"@jupyterlab/pdf-extension": "^4.1.0-beta.0",
166+
"@jupyterlab/pluginmanager-extension": "^4.1.0-beta.0",
166167
"@jupyterlab/running-extension": "^4.1.0-beta.0",
167168
"@jupyterlab/settingeditor": "^4.1.0-beta.0",
168169
"@jupyterlab/settingeditor-extension": "^4.1.0-beta.0",
@@ -284,6 +285,7 @@
284285
"@jupyterlab/notebook-extension:tracker",
285286
"@jupyterlab/notebook-extension:widget-factory"
286287
],
288+
"@jupyterlab/pluginmanager-extension": true,
287289
"@jupyterlab/shortcuts-extension": true,
288290
"@jupyterlab/terminal-extension": true,
289291
"@jupyterlab/theme-light-extension": true,

packages/application-extension/schema/shell.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"title": "Customize shell widget positioning",
1010
"description": "Overrides default widget position in the application layout",
1111
"default": {
12-
"Markdown Preview": { "area": "right" }
12+
"Markdown Preview": { "area": "right" },
13+
"Plugins": { "area": "left" }
1314
}
1415
}
1516
},

packages/application/src/app.ts

+25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the terms of the Modified BSD License.
33

44
import {
5+
JupyterLab,
56
JupyterFrontEnd,
67
JupyterFrontEndPlugin,
78
} from '@jupyterlab/application';
@@ -40,6 +41,17 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
4041
}
4142
}
4243

44+
// Create an IInfo dictionary from the options to override the defaults.
45+
const info = Object.keys(JupyterLab.defaultInfo).reduce((acc, val) => {
46+
if (val in options) {
47+
(acc as any)[val] = JSON.parse(JSON.stringify((options as any)[val]));
48+
}
49+
return acc;
50+
}, {} as Partial<JupyterLab.IInfo>);
51+
52+
// Populate application info.
53+
this._info = { ...JupyterLab.defaultInfo, ...info };
54+
4355
this.restored = this.shell.restored;
4456

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

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

86+
/**
87+
* The NotebookApp application information dictionary.
88+
*/
89+
get info(): JupyterLab.IInfo {
90+
return this._info;
91+
}
92+
7493
/**
7594
* The JupyterLab application paths dictionary.
7695
*/
@@ -149,6 +168,7 @@ export class NotebookApp extends JupyterFrontEnd<INotebookShell> {
149168
});
150169
}
151170

171+
private _info: JupyterLab.IInfo = JupyterLab.defaultInfo;
152172
private _formatter = new Throttler(() => {
153173
Private.setFormat(this);
154174
}, 250);
@@ -173,6 +193,11 @@ export namespace NotebookApp {
173193
* The mime renderer extensions.
174194
*/
175195
readonly mimeExtensions: IRenderMime.IExtensionModule[];
196+
197+
/**
198+
* The information about available plugins.
199+
*/
200+
readonly availablePlugins: JupyterLab.IPluginInfo[];
176201
}
177202

178203
/**

yarn.lock

+15
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,7 @@ __metadata:
21652165
"@jupyterlab/metadataform-extension": ^4.1.0-beta.0
21662166
"@jupyterlab/notebook-extension": ^4.1.0-beta.0
21672167
"@jupyterlab/pdf-extension": ^4.1.0-beta.0
2168+
"@jupyterlab/pluginmanager-extension": ^4.1.0-beta.0
21682169
"@jupyterlab/running-extension": ^4.1.0-beta.0
21692170
"@jupyterlab/settingeditor": ^4.1.0-beta.0
21702171
"@jupyterlab/settingeditor-extension": ^4.1.0-beta.0
@@ -3898,6 +3899,20 @@ __metadata:
38983899
languageName: node
38993900
linkType: hard
39003901

3902+
"@jupyterlab/pluginmanager-extension@npm:^4.1.0-beta.0":
3903+
version: 4.1.0-beta.0
3904+
resolution: "@jupyterlab/pluginmanager-extension@npm:4.1.0-beta.0"
3905+
dependencies:
3906+
"@jupyterlab/application": ^4.1.0-beta.0
3907+
"@jupyterlab/apputils": ^4.2.0-beta.0
3908+
"@jupyterlab/pluginmanager": ^4.1.0-beta.0
3909+
"@jupyterlab/translation": ^4.1.0-beta.0
3910+
"@jupyterlab/ui-components": ^4.1.0-beta.0
3911+
"@lumino/coreutils": ^2.1.2
3912+
checksum: 70a2defa672b2e273d304846d5e7a0ca8f9b617787044fc65bc5332403f0d7d3f78ce9e2eee8d7b1d1085f806b084e2f12e3e1e6a9a83f0905e9a927982593e0
3913+
languageName: node
3914+
linkType: hard
3915+
39013916
"@jupyterlab/pluginmanager@npm:^4.1.0-beta.0":
39023917
version: 4.1.0-beta.0
39033918
resolution: "@jupyterlab/pluginmanager@npm:4.1.0-beta.0"

0 commit comments

Comments
 (0)