Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/md/how_to/python/jupyterlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,27 @@ Perspective also exposes a JS-only `mimerender-extension`. This lets you view
this by right clicking one of these files and `Open With->CSVPerspective` (or
`JSONPerspective` or `ArrowPerspective`). Perspective will also install itself
as the default handler for opening `.arrow` files. -->

## Depending on Perspective in your own JupyterLab Widget

Perspective provides a [token for integration with JupyterLab's federated dependency model](https://jupyterlab.readthedocs.io/en/stable/extension/extension_dev.html#plugins-interacting-with-each-other).
This allows your plugin to simply depend on Perspective for initialization.

In your plugin code:

```javascript
import {IPerspective} from "@finos/perspective-jupyterlab";

export const MyCoolPlugin = {
activate,
id: "my-cool-plugin",
requires: [IPerspective],
autoStart: true,
};

// to use perspective, simply import. No initialization required
import perspective from "@finos/perspective";
```

And remember to add `perspective-python` as a python dependency, to ensure
the Perspective JupyterLab extension is installed.
29 changes: 26 additions & 3 deletions packages/perspective-jupyterlab/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
"build": "node ./build.mjs",
"clean": "node ./clean.mjs",
"test:jupyter": "__JUPYTERLAB_PORT__=6538 npx playwright test --config ../../tools/perspective-test/playwright.config.ts -- --jupyter",
"test:jupyter:build": "node ./build.mjs --test"
"test:jupyter:build": "node ./build.mjs --test",
"test:jupyter:extension": "jupyter labextension build test/extension"
},
"dependencies": {
"@finos/perspective": "workspace:",
"@finos/perspective-viewer": "workspace:",
"@finos/perspective-viewer-d3fc": "workspace:",
"@finos/perspective-viewer-datagrid": "workspace:",
"@finos/perspective-viewer-openlayers": "workspace:",
"@finos/perspective-viewer": "workspace:",
"@finos/perspective": "workspace:",
"@jupyter-widgets/base": ">2 <5",
"@jupyterlab/application": ">2 <5",
"@lumino/application": "<3",
"@lumino/coreutils": "<3",
"@lumino/widgets": "<3"
},
"devDependencies": {
Expand All @@ -39,6 +41,7 @@
"@jupyterlab/builder": "^4",
"@prospective.co/procss": "^0.1.16",
"copy-webpack-plugin": "~12",
"webpack": "catalog:",
"zx": "^8.1.8"
},
"jupyterlab": {
Expand All @@ -49,6 +52,26 @@
"@jupyter-widgets/base": {
"bundled": false,
"singleton": true
},
"@finos/perspective": {
"bundled": true,
"singleton": true
},
"@finos/perspective-viewer": {
"bundled": true,
"singleton": true
},
"@finos/perspective-viewer-d3fc": {
"bundled": true,
"singleton": true
},
"@finos/perspective-viewer-datagrid": {
"bundled": true,
"singleton": true
},
"@finos/perspective-viewer-openlayers": {
"bundled": true,
"singleton": true
}
},
"discovery": {
Expand Down
1 change: 1 addition & 0 deletions packages/perspective-jupyterlab/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ await Promise.all([
]);

export * from "./model";
export * from "./tokens";
export * from "./version";
export * from "./view";
export * from "./widget";
Expand Down
16 changes: 16 additions & 0 deletions packages/perspective-jupyterlab/src/js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@

import { IJupyterWidgetRegistry } from "@jupyter-widgets/base";
import { PerspectiveModel } from "./model";
import {
IPerspective,
IPerspectiveJupyterlab,
IPerspectiveViewer,
IPerspectiveViewerD3fc,
IPerspectiveViewerDatagrid,
IPerspectiveViewerOpenlayers,
} from "./tokens";
import { PerspectiveView } from "./view";
import { PERSPECTIVE_VERSION } from "./version";
const EXTENSION_ID = "@finos/perspective-jupyterlab";
Expand All @@ -24,6 +32,14 @@ export const PerspectiveJupyterPlugin = {
id: EXTENSION_ID,
// @ts-ignore
requires: [IJupyterWidgetRegistry],
provides: [
IPerspective,
IPerspectiveJupyterlab,
IPerspectiveViewer,
IPerspectiveViewerD3fc,
IPerspectiveViewerDatagrid,
IPerspectiveViewerOpenlayers,
],
activate: (app, registry) => {
registry.registerWidget({
name: EXTENSION_ID,
Expand Down
28 changes: 28 additions & 0 deletions packages/perspective-jupyterlab/src/js/tokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import { Token } from "@lumino/coreutils";

export const IPerspective = new Token("@finos/perspective");
export const IPerspectiveJupyterlab = new Token(
"@finos/perspective-jupyterlab",
);
export const IPerspectiveViewer = new Token("@finos/perspective-viewer");
export const IPerspectiveViewerD3fc = new Token(
"@finos/perspective-viewer-d3fc",
);
export const IPerspectiveViewerDatagrid = new Token(
"@finos/perspective-viewer-datagrid",
);
export const IPerspectiveViewerOpenlayers = new Token(
"@finos/perspective-viewer-openlayers",
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import { IPerspective } from "@finos/perspective-jupyterlab";

module.exports = [
{
id: "@finos/perspective-test-federated",
autoStart: true,
requires: [IPerspective],
activate: () => "hello",
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@finos/perspective-test-federated",
"version": "0.0.0",
"private": true,
"scripts": {},
"dependencies": {
"@finos/perspective-jupyterlab": "file:../../.."
},
"devDependencies": {
"@jupyterlab/builder": "^4"
},
"publishConfig": {
"access": "public"
},
"jupyterlab": {
"extension": true,
"outputDir": "./dist",
"sharedPackages": {
"@finos/perspective": {
"bundled": false,
"singleton": true
},
"@finos/perspective-viewer": {
"bundled": false,
"singleton": true
},
"@finos/perspective-viewer-d3fc": {
"bundled": false,
"singleton": true
},
"@finos/perspective-viewer-datagrid": {
"bundled": false,
"singleton": true
},
"@finos/perspective-viewer-openlayers": {
"bundled": false,
"singleton": true
}
}
}
}
Empty file.
22 changes: 22 additions & 0 deletions packages/perspective-jupyterlab/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

const CopyPlugin = require("copy-webpack-plugin");
const webpack = require("webpack");
const { ModuleFederationPlugin } = webpack.container;
const packageData = require("./package.json");

const shared = Object.keys(packageData.jupyterlab.sharedPackages)
.filter((pkg) => pkg.startsWith("@finos/perspective"))
.reduce((obj, pkg) => {
obj[pkg] = {
singleton: true,
packageName: pkg,
requiredVersion: require(`${pkg}/package.json`).version,
};
return obj;
}, {});

module.exports = {
experiments: {
Expand All @@ -20,5 +34,13 @@ module.exports = {
new CopyPlugin({
patterns: [{ from: "./install.json", to: "../install.json" }],
}),
new ModuleFederationPlugin({
library: {
type: "var",
name: ["PERSPECTIVE"],
},
name: "PERSPECTIVE",
shared,
}),
],
};
24 changes: 15 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading