Skip to content

Commit 4dded6c

Browse files
authored
Merge pull request #5096 from plotly/notebook-connected-default
Add back the mime renderer JL extension
2 parents 3d262d7 + 60735fe commit 4dded6c

22 files changed

+14225
-4728
lines changed

Diff for: .circleci/config.yml

+10-23
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ commands:
5858
source .venv/bin/activate
5959
uv pip install .
6060
uv pip install -r ./test_requirements/requirements_optional.txt
61-
cd js
62-
npm ci
63-
npm run build
6461
6562
- when:
6663
condition:
@@ -269,22 +266,18 @@ jobs:
269266

270267
steps:
271268
- checkout
272-
273269
- run:
274-
name: initial NPM Build
270+
name: PyPI Build
275271
command: |
276-
python -m venv venv
277-
. venv/bin/activate
272+
curl -LsSf https://astral.sh/uv/install.sh | sh
273+
uv venv
274+
source .venv/bin/activate
275+
uv pip install build
276+
uv pip install jupyter
278277
cd js
279278
npm ci
280279
npm run build
281-
git status
282-
283-
- run:
284-
name: PyPI Build
285-
command: |
286-
. venv/bin/activate
287-
pip install build
280+
cd ..
288281
python -m build --sdist --wheel -o dist
289282
cp -R dist output
290283
git status
@@ -310,7 +303,6 @@ jobs:
310303
- checkout
311304
- browser-tools/install-chrome
312305
- browser-tools/install-chromedriver
313-
314306
- run:
315307
name: Install dependencies
316308
command: |
@@ -319,16 +311,11 @@ jobs:
319311
uv venv
320312
source .venv/bin/activate
321313
uv pip install -r requirements.txt
314+
cd ..
322315
if [ "${CIRCLE_BRANCH}" != "doc-prod" ]; then
323316
uv pip uninstall plotly
324-
cd ..
325317
uv pip install -e .
326-
cd js
327-
npm ci
328-
npm run build
329-
cd ../doc
330318
fi
331-
cd ..
332319
333320
- run:
334321
name: make html
@@ -420,7 +407,7 @@ workflows:
420407
release_build:
421408
jobs:
422409
- full_build
423-
410+
424411
build:
425412
jobs:
426413
- test_core_py:
@@ -449,4 +436,4 @@ workflows:
449436
pandas_version: "1.2.4"
450437
numpy_version: "1.26.4"
451438
- python_311_percy
452-
- build-doc
439+
- build-doc

Diff for: .github/workflows/check-js-build.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
on: push
2+
3+
jobs:
4+
check-js-build:
5+
name: Check JS build artifacts
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- name: Set up Python
10+
uses: actions/setup-python@v5
11+
with:
12+
python-version: "3.x"
13+
14+
- name: Install Node
15+
uses: actions/setup-node@v2
16+
with:
17+
node-version: '22'
18+
19+
- name: Copy current files to a temporary directory
20+
run: |
21+
cp -R plotly/labextension/ plotly/labextension-tmp/
22+
23+
- name: Install dependencies and build
24+
run: |
25+
curl -LsSf https://astral.sh/uv/install.sh | sh
26+
uv venv
27+
source .venv/bin/activate
28+
uv pip install jupyter
29+
cd js
30+
npm ci
31+
npm run build
32+
- name: Check JupyterLab build artifacts
33+
run: |
34+
# 1. Hash contents of all static files, sort by content hash
35+
find plotly/labextension/static -type f -exec sha256sum {} \; | awk '{print $1}' | sort > new_hashes.txt
36+
find plotly/labextension-tmp/static -type f -exec sha256sum {} \; | awk '{print $1}' | sort > old_hashes.txt
37+
38+
# 2. Compare the sorted content hashes
39+
diff old_hashes.txt new_hashes.txt > content_diff.txt
40+
41+
# Remove the "load" line from both package.json files before comparing
42+
grep -v '"load": "static/' plotly/labextension/package.json > pkg1.json
43+
grep -v '"load": "static/' plotly/labextension-tmp/package.json > pkg2.json
44+
45+
# Compare stripped versions
46+
diff pkg1.json pkg2.json > package_json_diff.txt
47+
48+
# 5. Final check
49+
if [ -s content_diff.txt ] || [ -s package_json_diff.txt ]; then
50+
echo "❌ Build artifacts differ:"
51+
echo "--- Unexpected diffs ---"
52+
cat content_diff.txt
53+
echo "--- Unexpected package.json diffs ---"
54+
cat package_json_diff.txt
55+
echo "Please replace the 'plotly/labextension' directory with the artifacts of this CI run."
56+
exit 1
57+
else
58+
echo "✅ Build artifacts match expected output (ignoring known 'load' hash in package.json)."
59+
fi
60+
61+
- name: Store the build artifacts from plotly/labextension
62+
uses: actions/upload-artifact@v4
63+
if: failure()
64+
with:
65+
name: labextension
66+
path: plotly/labextension

Diff for: .github/workflows/test-release.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ jobs:
1010

1111
steps:
1212
- uses: actions/checkout@v4
13-
with:
14-
persist-credentials: false
1513
- name: Set up Python
1614
uses: actions/setup-python@v5
1715
with:
@@ -20,7 +18,7 @@ jobs:
2018
- name: Install Node
2119
uses: actions/setup-node@v2
2220
with:
23-
node-version: '18'
21+
node-version: '22'
2422

2523
- name: Install npm dependencies
2624
run: |

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ doc/python/.mapbox_token
5959
doc/.ipynb_checkpoints
6060
tags
6161
doc/check-or-enforce-order.py
62-
plotly/package_data/widgetbundle.js
6362

6463
tests/percy/*.html
6564
tests/percy/pandas2/*.html

Diff for: CONTRIBUTING.md

+13
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,19 @@ and
169169
[`pip`](https://pip.pypa.io/en/stable/reference/pip_install/#install-editable)
170170
documentation on _development mode_.
171171

172+
### Updating the `js/` directory
173+
**This is only necessary if you're making changes to files in the `js/` directory.**
174+
If you make changes to any files in the `js/` directory, you must run `npm install && npm run build` from the `js/` directory to rebuild the FigureWidget and JupyterLab extension.
175+
You must then commit the build artifacts produced in `plotly/labextension`. A CI job will verify that this step has been done correctly.
176+
177+
**Notes on the contents of the `js/` directory:**
178+
The `js/` directory contains Javascript code which helps with using Plotly in Jupyter notebooks.
179+
180+
There are two kinds of Jupyter support included in the `js/` directory:
181+
1. **Mime Renderer JupyterLab extension**: This is the default renderer for Plotly `Figure()` objects in Jupyter notebooks. The Plotly mime renderer JupyterLab extension is used automatically by JupyterLab / Jupyter Notebook
182+
when it sees the mimetype `application/vnd.plotly.v1+json` in the notebook output. The mime renderer loads `plotly.js` a single time and references it each time a Plotly figure is used in the notebook. This allows us to avoid embedding `plotly.js` in the notebook output. The JupyterLab extension source code is located at `js/src/mimeExtension.ts` and the compiled extension code is located at `plotly/labextension` in the built Python package. The command `jupyter labextension build` (which is one of the steps called by `npm run build`) compiles the extension and places the build artifacts in `plotly/labextension`.
183+
2. **FigureWidget**: This is a more-interactive method for rendering Plotly charts in notebooks. FigureWidget used by creating a `FigureWidget()` object inside the notebook code (in place of a `Figure()`). It allows for communication between the Javascript frontend and Python backend, and requires the installation of an additional Python package (`anywidget`). The FigureWidget source code is located at `js/src/widget.ts`, and is included in the built Python package at `plotly/package_data/widgetbundle.js`.
184+
172185
### Configure black code formatting
173186

174187
This repo uses the [Black](https://black.readthedocs.io/en/stable/) code formatter,

Diff for: js/install.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"schemaVersion": 1,
3+
"name": "jupyterlab-plotly",
4+
"version": "6.0.1",
5+
"jupyterlab": {
6+
"mimeExtension": "lib/mimeExtension.js"
7+
}
8+
}
9+

Diff for: js/lib/mimeExtension.js

+3,865
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)