Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit febc892

Browse files
committed
Update JupyterLab extension build process, and automate extension installation
1 parent 2e2c3a8 commit febc892

File tree

6 files changed

+156
-13
lines changed

6 files changed

+156
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
/extensions/jupyterlab/node_modules/
44
/extensions/jupyterlab/*.tgz
55
/dist
6+
/build/
7+
/extensions/jupyterlab/dist/

MANIFEST.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
recursive-include jupyter_dash/nbextension *.json
2-
recursive-include jupyter_dash/nbextension *.js
3-
recursive-include extensions/jupyterlab/*.tgz
1+
include jupyter_dash/nbextension *.json
2+
include jupyter_dash/nbextension *.js
3+
include jupyter_dash/labextension/package.json
4+
include jupyter_dash/labextension/dist *.tgz

extensions/jupyterlab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab-dash",
3-
"version": "0.2.0-alpha.2",
3+
"version": "0.2.0-alpha.4",
44
"description": "A JupyterLab extensions for rendering Plotly Dash apps",
55
"keywords": [
66
"jupyter",

jupyter_dash/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,3 @@ def _jupyter_nbextension_paths():
1111
"require": "jupyter_dash/main",
1212
}
1313
]
14-
15-
16-
__labextension_version__ = "v0.2.0-alpha.2"
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "jupyterlab-dash",
3+
"version": "0.2.0-alpha.4",
4+
"description": "A JupyterLab extensions for rendering Plotly Dash apps",
5+
"keywords": [
6+
"jupyter",
7+
"jupyterlab",
8+
"jupyterlab-extension"
9+
],
10+
"homepage": "https://github.com/plotly/jupyterlab-dash",
11+
"bugs": {
12+
"url": "https://github.com/plotly/jupyterlab-dash/issues"
13+
},
14+
"license": "MIT",
15+
"author": "Plotly",
16+
"files": [
17+
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
18+
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
19+
],
20+
"main": "lib/index.js",
21+
"types": "lib/index.d.ts",
22+
"repository": {
23+
"type": "git",
24+
"url": "git+https://github.com/plotly/jupyterlab-dash.git"
25+
},
26+
"scripts": {
27+
"build": "tsc",
28+
"clean": "rimraf lib",
29+
"prepare": "npm run clean && npm run build",
30+
"prettier": "prettier --write '{!(package),src/**,!(lib)/**}{.js,.jsx,.ts,.tsx,.css,.json,.md}'",
31+
"watch": "tsc -w"
32+
},
33+
"dependencies": {
34+
"@jupyterlab/application": "^2.0.0",
35+
"@jupyterlab/notebook": "^2.0.0",
36+
"@jupyterlab/console": "^2.0.0"
37+
},
38+
"devDependencies": {
39+
"prettier": "^1.11.1",
40+
"rimraf": "^2.6.1",
41+
"typescript": "~3.8.3"
42+
},
43+
"jupyterlab": {
44+
"extension": true
45+
}
46+
}

setup.py

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,106 @@
1-
from setuptools import setup
1+
import os
2+
import shutil
3+
from subprocess import check_call
4+
import json
5+
import time
6+
7+
from setuptools import setup, Command
8+
from setuptools.command.sdist import sdist
9+
from setuptools.command.build_py import build_py
10+
from setuptools.command.egg_info import egg_info
11+
12+
here = os.path.dirname(os.path.abspath(__file__))
13+
is_repo = os.path.exists(os.path.join(here, ".git"))
14+
15+
16+
def get_labextension_version():
17+
if is_repo:
18+
labextension_dir = os.path.join(here, "extensions", "jupyterlab")
19+
else:
20+
labextension_dir = os.path.join(here, "jupyter_dash", "labextension")
21+
22+
package_json = os.path.join(labextension_dir, 'package.json')
23+
with open(package_json, 'rt') as f:
24+
package_data = json.load(f)
25+
26+
labextension_version = package_data['version']
27+
return labextension_version
28+
29+
30+
def js_prerelease(command):
31+
"""decorator for building JavaScript extensions before command"""
32+
class DecoratedCommand(command):
33+
def run(self):
34+
self.run_command("build_js")
35+
command.run(self)
36+
return DecoratedCommand
37+
38+
39+
class BuildLabextension(Command):
40+
description = "Build JupyterLab extension"
41+
user_options = []
42+
43+
def initialize_options(self):
44+
pass
45+
46+
def finalize_options(self):
47+
pass
48+
49+
def run(self):
50+
if not is_repo:
51+
# Nothing to do
52+
return
53+
54+
# Load labextension version from package.json
55+
out_labextension_dir = os.path.join(here, "jupyter_dash", "labextension")
56+
os.makedirs(out_labextension_dir, exist_ok=True)
57+
58+
# Copy package.json to labextension directory
59+
shutil.copy(
60+
os.path.join(here, "extensions", "jupyterlab", "package.json"),
61+
out_labextension_dir
62+
)
63+
time.sleep(0.5)
64+
in_labextension_dir = os.path.join(here, "extensions", "jupyterlab")
65+
66+
# Build filename
67+
labextension_version = get_labextension_version()
68+
filename = "jupyterlab-dash-v{ver}.tgz".format(
69+
ver=labextension_version
70+
)
71+
72+
# Build and pack extension
73+
dist_path = os.path.join(out_labextension_dir, "dist")
74+
shutil.rmtree(dist_path, ignore_errors=True)
75+
os.makedirs(dist_path, exist_ok=True)
76+
77+
check_call(
78+
['jlpm', "install"],
79+
cwd=in_labextension_dir,
80+
)
81+
check_call(
82+
['jlpm', "build"],
83+
cwd=in_labextension_dir,
84+
)
85+
check_call(
86+
['jlpm', "pack", "--filename", dist_path + "/" + filename],
87+
cwd=in_labextension_dir,
88+
)
289

3-
from jupyter_dash import __labextension_version__
490

591
setup(
692
name='jupyter-dash',
7-
version='0.0.1a1',
93+
version='0.0.1a2',
894
description="Dash support for the Jupyter notebook interface",
995
author='Plotly',
1096
packages=['jupyter_dash'],
1197
install_requires=['dash', 'requests', 'flask', 'retrying', 'ipython'],
1298
include_package_data=True,
99+
package_data={
100+
"jupyter_dash": [
101+
"labextension/package.json",
102+
],
103+
},
13104
data_files=[
14105
# like `jupyter nbextension install --sys-prefix`
15106
("share/jupyter/nbextensions/jupyter_dash", [
@@ -21,9 +112,15 @@
21112
]),
22113
# Place jupyterlab extension in extension directory
23114
("share/jupyter/lab/extensions", [
24-
"extensions/jupyterlab/jupyterlab-dash-{ver}.tgz".format(
25-
ver=__labextension_version__
115+
"jupyter_dash/labextension/dist/jupyterlab-dash-v{ver}.tgz".format(
116+
ver=get_labextension_version()
26117
)
27118
]),
28-
]
119+
],
120+
cmdclass=dict(
121+
build_js=BuildLabextension,
122+
build_py=js_prerelease(build_py),
123+
egg_info=js_prerelease(egg_info),
124+
sdist=js_prerelease(sdist),
125+
)
29126
)

0 commit comments

Comments
 (0)