Skip to content

Commit 6c0053c

Browse files
authored
feat: support for jupyterlab (#271)
- uses prebuilt js that can be distributed in python package - swaps jquery ui to use version managed by the jquery ui team - updates @jupyterlab-widgets/base to support newer versions (for jlab3) - slightly tidied (?) the setup.py script
1 parent efac7a9 commit 6c0053c

File tree

9 files changed

+50
-32
lines changed

9 files changed

+50
-32
lines changed

install.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageManager": "python",
3+
"packageName": "graph-notebook",
4+
"uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package graph-notebook"
5+
}

setup.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@
1010
combine_commands, HERE, widgets_root
1111
)
1212

13-
nb_path = pjoin(HERE, 'src', 'graph_notebook', 'widgets', 'nbextension', 'static')
14-
lab_path = pjoin(HERE, 'src', 'graph_notebook', 'widgets', 'labextension')
13+
nb_path = pjoin(widgets_root, 'nbextension')
14+
lab_path = pjoin(widgets_root, 'labextension')
1515

1616
js_targets = [
1717
pjoin(nb_path, 'index.js'),
18-
pjoin(HERE, 'src', 'graph_notebook', 'widgets', 'lib', 'plugin.d.ts')
18+
pjoin(lab_path, 'package.json')
1919
]
2020

2121
package_data_spec = {
2222
'graph_notebook_widgets': [
23-
'nbextension/static/*.*js*',
24-
'labextension/*.tgz'
23+
'nbextension/**js*',
24+
'labextension/**'
2525
]
2626
}
2727

2828
data_files_spec = [
29-
('share/jupyter/nbextensions/graph_notebook_widgets',
30-
nb_path, '*.js*'),
31-
('share/jupyter/lab/extensions', lab_path, '*.tgz'),
29+
('share/jupyter/nbextensions/graph_notebook_widgets', nb_path, '**'),
30+
('share/jupyter/labextensions/graph_notebook_widgets', lab_path, '**'),
31+
('share/jupyter/labextensions/graph_notebook_widgets', HERE, 'install.json'),
3232
('etc/jupyter/nbconfig/notebook.d', HERE, 'graph_notebook_widgets.json')
3333
]
3434

3535
cmd_class = create_cmdclass('jsdeps', package_data_spec=package_data_spec, data_files_spec=data_files_spec)
3636
cmd_class['jsdeps'] = combine_commands(
37-
install_npm(widgets_root, build_cmd='build:all'),
37+
install_npm(widgets_root, build_cmd='build:prod'),
3838
ensure_targets(js_targets),
3939
)
4040

@@ -88,8 +88,8 @@ def get_version():
8888
'markupsafe<2.1.0'
8989
],
9090
package_data={
91-
'graph_notebook': ['graph_notebook/widgets/nbextensions/static/*.js',
92-
'graph_notebook/widgets/labextension/*.tgz'],
91+
'graph_notebook': ['graph_notebook/widgets/nbextensions/**',
92+
'graph_notebook/widgets/labextension/**'],
9393
'': ['*.ipynb', '*.html', '*.css', '*.js', '*.txt', '*.json', '*.ts', '*.css', '*.yaml', '*.md', '*.tgz']
9494
},
9595
cmdclass=cmd_class,

setupbase.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def run(self):
384384

385385
# ensure that __init__.py files are added to generated directories, otherwise it will not be packaged with
386386
# package distribution to pypi
387-
dirs_from_node_path = ['nbextension', pjoin('nbextension', 'static'), 'lib', 'labextension']
387+
dirs_from_node_path = ['nbextension', 'nbextension', 'lib', 'labextension']
388388
for init_path in dirs_from_node_path:
389389
full_path = pjoin(node_package, init_path, '__init__.py')
390390
with open(full_path, 'w+'):

src/graph_notebook/widgets/package.json

+27-15
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@
44
"author": "amazon",
55
"description": "A Custom Jupyter Library for rendering NetworkX MultiDiGraphs using vis-network",
66
"dependencies": {
7-
"@jupyter-widgets/base": "2.0.2",
7+
"@jupyter-widgets/base": "^2 || ^3 || ^4",
88
"feather-icons": "4.28.0",
9-
"jquery": "3.5.1",
10-
"jqueryui": "1.11.1",
9+
"jquery": "3.6.0",
10+
"jquery-ui": "1.13.1",
1111
"lodash": "4.17.21",
1212
"vis-data": "6.5.1",
1313
"vis-network": "7.6.3",
1414
"vis-util": "4.0.0"
1515
},
1616
"devDependencies": {
17+
"@jupyterlab/builder": "^3.0.0",
1718
"@phosphor/application": "1.7.3",
1819
"@phosphor/widgets": "1.9.3",
1920
"@types/chai": "4.2.11",
@@ -62,7 +63,14 @@
6263
"css/*.css"
6364
],
6465
"jupyterlab": {
65-
"extension": "lib/plugin"
66+
"extension": "lib/plugin",
67+
"outputDir": "labextension",
68+
"sharedPackages": {
69+
"@jupyter-widgets/base": {
70+
"bundled": false,
71+
"singleton": true
72+
}
73+
}
6674
},
6775
"keywords": [
6876
"jupyter",
@@ -74,19 +82,23 @@
7482
"main": "lib/index.js",
7583
"types": "lib/index.d.ts",
7684
"scripts": {
77-
"build": "webpack -p",
85+
"build": "npm run build:lib && npm run build:nbextension && npm run build:labextension:dev",
86+
"build:prod": "npm run build:lib && npm run build:nbextension && npm run build:labextension",
87+
"build:labextension": "jupyter labextension build .",
88+
"build:labextension:dev": "jupyter labextension build --development True .",
7889
"build:lib": "tsc",
79-
"build:labextension": "mkdirp labextension && cd labextension && npm pack ../",
80-
"build:all": "npm run build && npm run build:labextension",
81-
"clean": "rimraf dist && rimraf docs && rimraf lib && rimraf nbextension && rimraf labextension",
82-
"dist": "npm run clean && npm run build:all",
83-
"dev": "npm run clean && webpack -d --config webpack.dev.config.js",
84-
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
85-
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --fix",
86-
"test": "karma start karma.conf.js",
87-
"start": "webpack-dev-server --config webpack.dev.config.js",
90+
"build:nbextension": "webpack",
91+
"clean": "npm run clean:lib && npm run clean:nbextension && npm run clean:labextension",
92+
"clean:lib": "rimraf lib",
93+
"clean:labextension": "rimraf labextension",
94+
"clean:nbextension": "rimraf nbextension",
95+
"lint": "eslint . --ext .ts,.tsx --fix",
96+
"lint:check": "eslint . --ext .ts,.tsx",
97+
"prepack": "npm run build:lib",
98+
"test": "jest",
8899
"watch": "npm-run-all -p watch:*",
89100
"watch:lib": "tsc -w",
90-
"watch:nbextension": "webpack --watch"
101+
"watch:nbextension": "webpack --watch --mode=development",
102+
"watch:labextension": "jupyter labextension watch ."
91103
}
92104
}

src/graph_notebook/widgets/src/force_widget.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ import { MODULE_NAME, MODULE_VERSION } from "./version";
2828

2929
import feather from "feather-icons";
3030
import $ from "jquery";
31-
import "jqueryui";
31+
import "jquery-ui/ui/widgets/draggable";
32+
import "jquery-ui/ui/widgets/resizable";
3233

3334
// Import the CSS
34-
import "./css/widget.css";
35+
import "../css/widget.css";
3536
import DraggableOptions = JQueryUI.DraggableOptions;
3637
import ResizableOptions = JQueryUI.ResizableOptions;
3738

src/graph_notebook/widgets/src/plugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ const plugin: IPlugin<Application<Widget>, void> = {
3737
requires: [IJupyterWidgetRegistry],
3838
activate: activateWidgetExtension,
3939
autoStart: true,
40-
};
40+
} as unknown as IPlugin<Application<Widget>, void>;
4141

4242
export default plugin;

src/graph_notebook/widgets/webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = [
5757
entry: "./src/extension.js",
5858
output: {
5959
filename: "extension.js",
60-
path: path.resolve(__dirname, "nbextension", "static"),
60+
path: path.resolve(__dirname, "nbextension"),
6161
libraryTarget: "var",
6262
},
6363
module: {
@@ -80,7 +80,7 @@ module.exports = [
8080
entry: "./src/extension.ts",
8181
output: {
8282
filename: "index.js",
83-
path: path.resolve(__dirname, "nbextension", "static"),
83+
path: path.resolve(__dirname, "nbextension"),
8484
// Using amd target without giving a library name requires the module being loaded by a RequireJS module loader.
8585
// See https://webpack.js.org/configuration/output/#outputlibrary and src/extension.js.
8686
libraryTarget: "amd",

0 commit comments

Comments
 (0)