Created
August 28, 2026 15:27
-
-
Save larsoner/e0decb518fd029daa5e8c3e8c3c3d084 to your computer and use it in GitHub Desktop.
plotly scraper demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Before/after demo for plotly/plotly.py#5701 (sphinx-gallery scraper rewrite). | |
| # Creates ./sgdemo and ./sgdemo-venv, builds the same one-example gallery with | |
| # released plotly and with the PR branch, and prints what to compare. | |
| set -euo pipefail | |
| mkdir -p sgdemo/examples | |
| # a rerun must not reuse sphinx-gallery's cache of executed examples | |
| rm -rf sgdemo/auto_examples sgdemo/_build_before sgdemo/_build_after | |
| cat > sgdemo/conf.py <<'EOF' | |
| project = "plotly-scraper-demo" | |
| extensions = ["sphinx_gallery.gen_gallery"] | |
| sphinx_gallery_conf = { | |
| "examples_dirs": "examples", | |
| "gallery_dirs": "auto_examples", | |
| # spelled out so the same conf works before and after the PR; | |
| # with the new plotly this can be just "plotly" | |
| "image_scrapers": ("plotly.io._sg_scraper.plotly_sg_scraper",), | |
| } | |
| EOF | |
| printf 'demo\n====\n.. toctree::\n\n auto_examples/index\n' > sgdemo/index.rst | |
| printf 'Examples\n========\n' > sgdemo/examples/GALLERY_HEADER.rst | |
| cat > sgdemo/examples/plot_demo.py <<'EOF' | |
| """ | |
| Plotly demo | |
| =========== | |
| """ | |
| import plotly.graph_objects as go | |
| fig = go.Figure(go.Bar(x=["a", "b", "c"], y=[1, 3, 2])) | |
| fig.show() | |
| EOF | |
| python3 -m venv sgdemo-venv | |
| PIP=sgdemo-venv/bin/pip | |
| PY=sgdemo-venv/bin/python | |
| $PIP install --quiet sphinx sphinx-gallery matplotlib pillow kaleido | |
| # pip can consider either plotly satisfied by the other (same version | |
| # number), so uninstall before each leg | |
| echo "=== BEFORE: released plotly ===" | |
| $PIP uninstall --quiet -y plotly 2>/dev/null || true | |
| $PIP install --quiet plotly | |
| $PY -m sphinx -b html sgdemo sgdemo/_build_before | |
| echo "=== AFTER: plotly from the PR branch ===" | |
| $PIP uninstall --quiet -y plotly | |
| $PIP install --quiet "plotly @ git+https://github.com/larsoner/plotly.py@sgthumb" | |
| rm -rf sgdemo/auto_examples # sphinx-gallery caches executed examples | |
| $PY -m sphinx -b html sgdemo sgdemo/_build_after | |
| cat <<'EOF' | |
| Compare the gallery thumbnail and the figure on the example page: | |
| before: sgdemo/_build_before/auto_examples/index.html | |
| (placeholder thumbnail; the figure is missing from the page) | |
| after: sgdemo/_build_after/auto_examples/index.html | |
| (real figure thumbnail; interactive figure on the page) | |
| The "after" build exports static images | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment