Skip to content

Commit eb5ecd1

Browse files
committed
Linting/formatting
1 parent d14b701 commit eb5ecd1

2 files changed

Lines changed: 105 additions & 96 deletions

File tree

test/image/make_baseline.py

Lines changed: 68 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,130 +5,138 @@
55
from convert_b64 import arraysToB64
66

77
args = []
8-
if len(sys.argv) == 2 :
8+
if len(sys.argv) == 2:
99
args = sys.argv[1].split()
10-
elif len(sys.argv) > 1 :
10+
elif len(sys.argv) > 1:
1111
args = sys.argv
1212

1313
root = os.getcwd()
1414

15-
virtual_webgl = os.path.join(root, 'node_modules', 'virtual-webgl', 'src', 'virtual-webgl.js')
16-
plotlyjs = os.path.join(root, 'build', 'plotly.js')
17-
plotlyjs_with_virtual_webgl = os.path.join(root, 'build', 'plotly_with_virtual-webgl.js')
15+
virtual_webgl = os.path.join(
16+
root, "node_modules", "virtual-webgl", "src", "virtual-webgl.js"
17+
)
18+
plotlyjs = os.path.join(root, "build", "plotly.js")
19+
plotlyjs_with_virtual_webgl = os.path.join(
20+
root, "build", "plotly_with_virtual-webgl.js"
21+
)
1822

19-
dirIn = os.path.join(root, 'test', 'image', 'mocks')
20-
dirOut = os.path.join(root, 'build', 'test_images')
23+
dirIn = os.path.join(root, "test", "image", "mocks")
24+
dirOut = os.path.join(root, "build", "test_images")
2125

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

24-
if '=' in args :
25-
args = args[args.index('=') + 1:]
26-
dirOut = os.path.join(root, 'test', 'image', 'baselines')
28+
if "=" in args:
29+
args = args[args.index("=") + 1 :]
30+
dirOut = os.path.join(root, "test", "image", "baselines")
2731

28-
if 'mathjax3=' in sys.argv :
29-
dirOut = os.path.join(root, 'test', 'image', 'baselines')
32+
if "mathjax3=" in sys.argv:
33+
dirOut = os.path.join(root, "test", "image", "baselines")
3034

31-
print('output to', dirOut)
35+
print("output to", dirOut)
3236

3337
mathjax_version = 2
34-
if 'mathjax3' in sys.argv or 'mathjax3=' in sys.argv :
38+
if "mathjax3" in sys.argv or "mathjax3=" in sys.argv:
3539
# until https://github.com/plotly/Kaleido/issues/124 is addressed
3640
# we are uanble to use local mathjax v3 installed in node_modules
3741
# for now let's download it from the internet:
38-
pio.kaleido.scope.mathjax = 'https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js'
42+
pio.kaleido.scope.mathjax = (
43+
"https://cdn.jsdelivr.net/npm/mathjax@3.2.2/es5/tex-svg.js"
44+
)
3945
mathjax_version = 3
40-
print('Kaleido using MathJax v3')
46+
print("Kaleido using MathJax v3")
4147

42-
virtual_webgl_version = 0 # i.e. virtual-webgl is not used
43-
if 'virtual-webgl' in sys.argv or 'virtual-webgl=' in sys.argv :
48+
virtual_webgl_version = 0 # i.e. virtual-webgl is not used
49+
if "virtual-webgl" in sys.argv or "virtual-webgl=" in sys.argv:
4450
virtual_webgl_version = 1
45-
print('using virtual-webgl for WebGL v1')
51+
print("using virtual-webgl for WebGL v1")
4652

47-
with open(plotlyjs_with_virtual_webgl, 'w') as fileOut:
53+
with open(plotlyjs_with_virtual_webgl, "w") as fileOut:
4854
for filename in [virtual_webgl, plotlyjs]:
49-
with open(filename, 'r') as fileIn:
55+
with open(filename, "r") as fileIn:
5056
for line in fileIn:
5157
fileOut.write(line)
5258

5359
plotlyjs = plotlyjs_with_virtual_webgl
5460

5561
pio.kaleido.scope.plotlyjs = plotlyjs
56-
pio.kaleido.scope.topojson = "file://" + os.path.join(root, 'topojson', 'dist')
57-
pio.templates.default = 'none'
62+
pio.kaleido.scope.topojson = "file://" + os.path.join(root, "topojson", "dist")
63+
pio.templates.default = "none"
5864

59-
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
65+
ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith(".json")]
6066
ALL_MOCKS.sort()
6167

62-
if len(args) > 0 :
68+
if len(args) > 0:
6369
allNames = [a for a in args if a in ALL_MOCKS]
64-
else :
70+
else:
6571
allNames = ALL_MOCKS
6672

6773
# unable to generate baselines for the following mocks
6874
blacklist = [
69-
'map_stamen-style',
70-
'map_predefined-styles2',
71-
'map_scattercluster',
72-
'map_fonts-supported-open-sans',
73-
'map_fonts-supported-open-sans-weight',
74-
'map_layers',
75+
"map_stamen-style",
76+
"map_predefined-styles2",
77+
"map_scattercluster",
78+
"map_fonts-supported-open-sans",
79+
"map_fonts-supported-open-sans-weight",
80+
"map_layers",
7581
]
7682
allNames = [a for a in allNames if a not in blacklist]
7783

78-
if len(allNames) == 0 :
79-
print('error: Nothing to create!')
84+
if len(allNames) == 0:
85+
print("error: Nothing to create!")
8086
sys.exit(1)
8187

8288
failed = []
83-
for name in allNames :
89+
for name in allNames:
8490
outName = name
85-
if mathjax_version == 3 :
86-
outName = 'mathjax3___' + name
91+
if mathjax_version == 3:
92+
outName = "mathjax3___" + name
8793

8894
print(outName)
8995

9096
created = False
9197

92-
MAX_RETRY = 2 # 1 means retry once
93-
for attempt in range(0, MAX_RETRY + 1) :
94-
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
98+
MAX_RETRY = 2 # 1 means retry once
99+
for attempt in range(0, MAX_RETRY + 1):
100+
with open(os.path.join(dirIn, name + ".json"), "r") as _in:
95101
fig = json.load(_in)
96102

97103
width = 700
98104
height = 500
99-
if 'layout' in fig :
100-
layout = fig['layout']
101-
if 'autosize' not in layout or layout['autosize'] != True :
102-
if 'width' in layout :
103-
width = layout['width']
104-
if 'height' in layout :
105-
height = layout['height']
106-
107-
if 'b64' in sys.argv or 'b64=' in sys.argv or 'b64-json' in sys.argv :
105+
if "layout" in fig:
106+
layout = fig["layout"]
107+
if "autosize" not in layout or layout["autosize"] != True:
108+
if "width" in layout:
109+
width = layout["width"]
110+
if "height" in layout:
111+
height = layout["height"]
112+
113+
if "b64" in sys.argv or "b64=" in sys.argv or "b64-json" in sys.argv:
108114
newFig = dict()
109115
arraysToB64(fig, newFig)
110116
fig = newFig
111-
if 'b64-json' in sys.argv and attempt == 0 : print(json.dumps(fig, indent = 2))
117+
if "b64-json" in sys.argv and attempt == 0:
118+
print(json.dumps(fig, indent=2))
112119

113-
try :
120+
try:
114121
pio.write_image(
115122
fig=fig,
116-
file=os.path.join(dirOut, outName + '.png'),
123+
file=os.path.join(dirOut, outName + ".png"),
117124
width=width,
118125
height=height,
119-
validate=False
126+
validate=False,
120127
)
121128
created = True
122-
except Exception as e :
129+
except Exception as e:
123130
print(e)
124-
if attempt < MAX_RETRY :
125-
print('retry', attempt + 1, '/', MAX_RETRY)
126-
else :
131+
if attempt < MAX_RETRY:
132+
print("retry", attempt + 1, "/", MAX_RETRY)
133+
else:
127134
failed.append(outName)
128135

129-
if(created) : break
136+
if created:
137+
break
130138

131-
if len(failed) > 0 :
132-
print('Failed at :')
139+
if len(failed) > 0:
140+
print("Failed at :")
133141
print(failed)
134142
sys.exit(1)

test/image/make_exports.py

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,63 @@
44
import plotly.io as pio
55

66
root = os.getcwd()
7-
dirIn = os.path.join(root, 'test', 'image', 'mocks')
8-
dirOut = os.path.join(root, 'build', 'test_images')
7+
dirIn = os.path.join(root, "test", "image", "mocks")
8+
dirOut = os.path.join(root, "build", "test_images")
99

10-
pio.templates.default = 'none'
11-
pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js')
10+
pio.templates.default = "none"
11+
pio.kaleido.scope.plotlyjs = os.path.join(root, "build", "plotly.js")
1212

13-
allFormats = ['svg', 'jpg', 'jpeg', 'webp', 'pdf']
13+
allFormats = ["svg", "jpg", "jpeg", "webp", "pdf"]
1414
# 'png' is tested by image-test
1515

1616
allNames = [
17-
'plot_types',
18-
'annotations',
19-
'shapes',
20-
'range_slider',
21-
'contour_legend-colorscale',
22-
'layout_image',
23-
'image_astronaut_source',
24-
'gl2d_no-clustering2',
25-
'gl3d_surface-heatmap-treemap_transparent-colorscale',
26-
'map_density-multiple_legend',
27-
'smith_modes',
28-
'zsmooth_methods',
29-
'fonts',
30-
'worldcup',
31-
'mathjax'
17+
"plot_types",
18+
"annotations",
19+
"shapes",
20+
"range_slider",
21+
"contour_legend-colorscale",
22+
"layout_image",
23+
"image_astronaut_source",
24+
"gl2d_no-clustering2",
25+
"gl3d_surface-heatmap-treemap_transparent-colorscale",
26+
"map_density-multiple_legend",
27+
"smith_modes",
28+
"zsmooth_methods",
29+
"fonts",
30+
"worldcup",
31+
"mathjax",
3232
]
3333

3434
failed = 0
35-
for name in allNames :
36-
for fmt in allFormats :
37-
print(name + ' --> ' + fmt)
35+
for name in allNames:
36+
for fmt in allFormats:
37+
print(name + " --> " + fmt)
3838

39-
with open(os.path.join(dirIn, name + '.json'), 'r') as _in :
39+
with open(os.path.join(dirIn, name + ".json"), "r") as _in:
4040
fig = json.load(_in)
4141

4242
width = 700
4343
height = 500
44-
if 'layout' in fig :
45-
layout = fig['layout']
46-
if 'autosize' not in layout or layout['autosize'] != True :
47-
if 'width' in layout :
48-
width = layout['width']
49-
if 'height' in layout :
50-
height = layout['height']
44+
if "layout" in fig:
45+
layout = fig["layout"]
46+
if "autosize" not in layout or layout["autosize"] != True:
47+
if "width" in layout:
48+
width = layout["width"]
49+
if "height" in layout:
50+
height = layout["height"]
5151

52-
try :
52+
try:
5353
pio.write_image(
5454
fig=fig,
55-
file=os.path.join(dirOut, name + '.' + fmt),
55+
file=os.path.join(dirOut, name + "." + fmt),
5656
width=width,
5757
height=height,
58-
validate=False
58+
validate=False,
5959
)
6060

61-
except Exception as e :
61+
except Exception as e:
6262
print(e)
6363
failed += 1
6464

65-
if failed > 0 : sys.exit(1)
65+
if failed > 0:
66+
sys.exit(1)

0 commit comments

Comments
 (0)