Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
use kaleido v1 for image tests
  • Loading branch information
emilykl committed Jul 28, 2025
commit 87df18634999779164272336a4477231e762e099
40 changes: 35 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,15 @@ jobs:
make-baselines-virtual-webgl:
parallelism: 8
docker:
- image: cimg/python:3.12.11
- image: cimg/python:3.12.11-browsers
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
install-chrome: true
chrome-version: "132.0.6834.110"
- attach_workspace:
at: ~/
- run: sudo apt-get update
Expand All @@ -236,9 +242,15 @@ jobs:

make-baselines-mathjax3:
docker:
- image: cimg/python:3.12.11
- image: cimg/python:3.12.11-browsers
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
install-chrome: true
chrome-version: "132.0.6834.110"
- attach_workspace:
at: ~/
- run: sudo apt-get update
Expand All @@ -256,9 +268,15 @@ jobs:
make-baselines:
parallelism: 12
docker:
- image: cimg/python:3.12.11
- image: cimg/python:3.12.11-browsers
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
install-chrome: true
chrome-version: "132.0.6834.110"
- attach_workspace:
at: ~/
- run: sudo apt-get update
Expand All @@ -276,9 +294,15 @@ jobs:
make-baselines-b64:
parallelism: 12
docker:
- image: cimg/python:3.12.11
- image: cimg/python:3.12.11-browsers
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
install-chrome: true
chrome-version: "132.0.6834.110"
- attach_workspace:
at: ~/
- run: sudo apt-get update
Expand Down Expand Up @@ -351,9 +375,15 @@ jobs:

make-exports:
docker:
- image: cimg/python:3.12.11
- image: cimg/python:3.12.11-browsers
working_directory: ~/plotly.js
steps:
- run: sudo apt-get update
- browser-tools/install-browser-tools:
install-firefox: false
install-geckodriver: false
install-chrome: true
chrome-version: "132.0.6834.110"
- attach_workspace:
at: ~/
- run: sudo apt-get update
Expand Down
2 changes: 1 addition & 1 deletion .circleci/env_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sudo apt install fontconfig
sudo fc-cache -f

# install kaleido & plotly
sudo python3 -m pip install kaleido==0.2.1 plotly==6.2.0 --progress-bar off
sudo python3 -m pip install "plotly[kaleido]==6.2.0" --progress-bar off

# install numpy i.e. to convert arrays to typed arrays
sudo python3 -m pip install numpy==1.24.2
139 changes: 82 additions & 57 deletions test/image/make_baseline.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import asyncio
import json
import os
import sys
import json

import kaleido
import plotly.io as pio

from convert_b64 import arraysToB64


args = []
if len(sys.argv) == 2 :
args = sys.argv[1].split()
Expand All @@ -19,7 +24,7 @@
dirIn = os.path.join(root, 'test', 'image', 'mocks')
dirOut = os.path.join(root, 'build', 'test_images')

# N.B. equal is the falg to write to baselines not test_images
# N.B. equal is the flag to write to baselines not test_images

if '=' in args :
args = args[args.index('=') + 1:]
Expand All @@ -31,11 +36,12 @@
print('output to', dirOut)

mathjax_version = 2
mathjax = None
if 'mathjax3' in sys.argv or 'mathjax3=' in sys.argv :
# until https://github.com/plotly/Kaleido/issues/124 is addressed
# we are uanble to use local mathjax v3 installed in node_modules
# for now let's download it from the internet:
pio.kaleido.scope.mathjax = 'https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg.js'
mathjax = 'https://cdn.jsdelivr.net/npm/[email protected]/es5/tex-svg.js'
mathjax_version = 3
print('Kaleido using MathJax v3')

Expand All @@ -52,8 +58,8 @@

plotlyjs = plotlyjs_with_virtual_webgl

pio.kaleido.scope.plotlyjs = plotlyjs
pio.kaleido.scope.topojson = "file://" + os.path.join(root, 'topojson', 'dist')
pio.defaults.plotlyjs = plotlyjs
pio.defaults.topojson = "file://" + os.path.join(root, 'topojson', 'dist')
pio.templates.default = 'none'

ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
Expand All @@ -79,55 +85,74 @@
sys.exit(1)

failed = []
for name in allNames :
outName = name
if mathjax_version == 3 :
outName = 'mathjax3___' + name

print(outName)

created = False

MAX_RETRY = 2 # 1 means retry once
for attempt in range(0, MAX_RETRY + 1) :
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
fig = json.load(_in)

width = 700
height = 500
if 'layout' in fig :
layout = fig['layout']
if 'autosize' not in layout or layout['autosize'] != True :
if 'width' in layout :
width = layout['width']
if 'height' in layout :
height = layout['height']

if 'b64' in sys.argv or 'b64=' in sys.argv or 'b64-json' in sys.argv :
newFig = dict()
arraysToB64(fig, newFig)
fig = newFig
if 'b64-json' in sys.argv and attempt == 0 : print(json.dumps(fig, indent = 2))

try :
pio.write_image(
fig=fig,
file=os.path.join(dirOut, outName + '.png'),
width=width,
height=height,
validate=False
)
created = True
except Exception as e :
print(e)
if attempt < MAX_RETRY :
print('retry', attempt + 1, '/', MAX_RETRY)
else :
failed.append(outName)

if(created) : break

if len(failed) > 0 :
print('Failed at :')
print(failed)
sys.exit(1)

async def make_baselines_async():

kopts = dict(
plotlyjs=plotlyjs,
)
if mathjax is not None:
kopts['mathjax'] = mathjax

async with kaleido.Kaleido(n=1, **kopts) as k:
for name in allNames:
outName = name
if mathjax_version == 3:
outName = 'mathjax3___' + name

print(outName)

created = False

MAX_RETRY = 2 # 1 means retry once
for attempt in range(0, MAX_RETRY + 1) :
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
fig = json.load(_in)

width = 700
height = 500
if 'layout' in fig :
layout = fig['layout']
if 'autosize' not in layout or layout['autosize'] != True :
if 'width' in layout :
width = layout['width']
if 'height' in layout :
height = layout['height']

if 'b64' in sys.argv or 'b64=' in sys.argv or 'b64-json' in sys.argv :
newFig = dict()
arraysToB64(fig, newFig)
fig = newFig
if 'b64-json' in sys.argv and attempt == 0 : print(json.dumps(fig, indent = 2))

try:
bytes = await k.calc_fig(
fig,
path=None,
opts=dict(
format="png",
width=width,
height=height,
),
)
filename = os.path.join(dirOut, outName + '.png')
with open(filename, "wb") as f:
f.write(bytes)
created = True
except Exception as e:
print(e)
if attempt < MAX_RETRY :
print('retry', attempt + 1, '/', MAX_RETRY)
else :
failed.append(outName)

if(created): break

if len(failed) > 0 :
print('Failed at :')
print(failed)
sys.exit(1)


if __name__ == "__main__":
asyncio.run(make_baselines_async())