28
28
"""
29
29
30
30
PLOT_SCHEMA_REPLACEMENTS = (
31
- ('*' , '"' ),
31
+ ("*" , '"' ),
32
32
("{array}" , "array" ),
33
33
("{arrays}" , "arrays" ),
34
34
("{object}" , "object" ),
49
49
"magic_underscores" ,
50
50
"role" ,
51
51
"stream" ,
52
- "transforms"
53
- "uid" ,
52
+ "transformsuid" ,
54
53
}
55
54
56
55
SKIP_MUSTMATCH = {
70
69
"yaxis" ,
71
70
}
72
71
73
- ANNOTATION = " " .join ([
74
- "<br>An annotation is a text element that can be placed anywhere in the plot." ,
75
- "It can be positioned with respect to relative coordinates in the plot" ,
76
- "or with respect to the actual data coordinates of the graph." ,
77
- "Annotations can be shown with or without an arrow." ,
78
- ])
72
+ ANNOTATION = " " .join (
73
+ [
74
+ "<br>An annotation is a text element that can be placed anywhere in the plot." ,
75
+ "It can be positioned with respect to relative coordinates in the plot" ,
76
+ "or with respect to the actual data coordinates of the graph." ,
77
+ "Annotations can be shown with or without an arrow." ,
78
+ ]
79
+ )
79
80
80
81
81
82
def main ():
@@ -93,23 +94,37 @@ def main():
93
94
continue
94
95
title = m .group (1 )
95
96
96
- if (m := INCLUDE_TRACE_RE .search (src_content )):
97
- if _log (m .group (1 ) != title , f"title { title } != include title { m .group (1 )} in { src_path } " ):
97
+ if m := INCLUDE_TRACE_RE .search (src_content ):
98
+ if _log (
99
+ m .group (1 ) != title ,
100
+ f"title { title } != include title { m .group (1 )} in { src_path } " ,
101
+ ):
98
102
continue
99
103
trace_name = m .group (2 )
100
104
trace_data = schema ["traces" ].get (trace_name , None )
101
- if _log (trace_data is None , f"trace '{ trace_name } ' not found in { args .schema } " ):
105
+ if _log (
106
+ trace_data is None , f"trace '{ trace_name } ' not found in { args .schema } "
107
+ ):
102
108
continue
103
109
html = _reference_trace (args , schema , src_path , trace_name , trace_data )
104
110
105
- elif ( m := INCLUDE_BLOCK_RE .search (src_content ) ):
111
+ elif m := INCLUDE_BLOCK_RE .search (src_content ):
106
112
parent_link = m .group (1 )
107
113
block = m .group (2 )
108
114
parent_path = m .group (3 )
109
115
mustmatch = m .group (4 )
110
116
accum = []
111
117
attributes = schema ["layout" ]["layoutAttributes" ]
112
- _reference_block (args , src_path , accum , attributes , parent_link , parent_path , block , mustmatch )
118
+ _reference_block (
119
+ args ,
120
+ src_path ,
121
+ accum ,
122
+ attributes ,
123
+ parent_link ,
124
+ parent_path ,
125
+ block ,
126
+ mustmatch ,
127
+ )
113
128
html = _replace_special ("" .join ([_str (a ) for a in accum ]))
114
129
115
130
else :
@@ -144,15 +159,21 @@ def _get(value, key, default=None):
144
159
145
160
def _parse_args ():
146
161
"""Parse command-line arguments."""
147
- parser = argparse .ArgumentParser (description = "Generate HTML reference documentation" )
162
+ parser = argparse .ArgumentParser (
163
+ description = "Generate HTML reference documentation"
164
+ )
148
165
parser .add_argument ("inputs" , nargs = "+" , type = Path , help = "Input Jekyll files" )
149
166
parser .add_argument ("--schema" , type = Path , help = "Path to plot schema JSON file" )
150
167
parser .add_argument ("--outdir" , type = Path , help = "Output directory" )
151
- parser .add_argument ("--verbose" , type = int , default = 0 , help = "Integer verbosity level" )
168
+ parser .add_argument (
169
+ "--verbose" , type = int , default = 0 , help = "Integer verbosity level"
170
+ )
152
171
return parser .parse_args ()
153
172
154
173
155
- def _reference_block (args , src_path , accum , attributes , parent_link , parent_path , block , mustmatch = None ):
174
+ def _reference_block (
175
+ args , src_path , accum , attributes , parent_link , parent_path , block , mustmatch = None
176
+ ):
156
177
"""Generate HTML documentation for a trace's attributes."""
157
178
accum .append ("<ul>\n " )
158
179
for key , value in attributes .items ():
@@ -168,7 +189,9 @@ def _reference_block(args, src_path, accum, attributes, parent_link, parent_path
168
189
accum .append (f" { key } \n " )
169
190
accum .append ("</a>\n " )
170
191
171
- accum .append (f"<br><em>Parent:</em> <code>{ parent_path .replace ('-' , '.' )} </code>\n " )
192
+ accum .append (
193
+ f"<br><em>Parent:</em> <code>{ parent_path .replace ('-' , '.' )} </code>\n "
194
+ )
172
195
173
196
if (key == "type" ) and (block == "data" ):
174
197
accum .append ("<br />\n " )
@@ -183,13 +206,17 @@ def _reference_block(args, src_path, accum, attributes, parent_link, parent_path
183
206
if _get (value , "items" ) and (_get (value , "valType" ) != "info_array" ):
184
207
_reference_block_array (src_path , accum , key , value )
185
208
elif _get (value , "role" ) == "object" :
186
- accum .append ('<br><em>Type:</em> {object} containing one or more of the keys listed below.\n ' )
209
+ accum .append (
210
+ "<br><em>Type:</em> {object} containing one or more of the keys listed below.\n "
211
+ )
187
212
188
213
if _get (value , "description" , "" ) != "" :
189
214
accum .append (f"<p>{ escape (value .get ('description' ))} </p>\n " )
190
215
191
216
if _get (value , "role" ) == "object" :
192
- _reference_block_object (args , src_path , accum , parent_link , parent_path , key , value )
217
+ _reference_block_object (
218
+ args , src_path , accum , parent_link , parent_path , key , value
219
+ )
193
220
194
221
accum .append ("</li>\n " )
195
222
accum .append ("</ul>\n " )
@@ -201,11 +228,13 @@ def _reference_block_valtype(src_path, accum, key, value):
201
228
inner = " " * 20
202
229
accum .append ("<br>\n " )
203
230
204
- if (_get (value , "valType" ) == "enumerated" ) or _get (_get (value , "valType" ), "values" ):
231
+ if (_get (value , "valType" ) == "enumerated" ) or _get (
232
+ _get (value , "valType" ), "values"
233
+ ):
205
234
accum .append (f"{ outer } <em>Type:</em>\n " )
206
235
accum .append (f"{ inner } { _get (value , 'valType' )} " )
207
236
if _get (value , "arrayOk" ):
208
- accum .append (f" or array of { _get (value , 'valType' )} s\n " )
237
+ accum .append (f" or array of { _get (value , 'valType' )} s\n " )
209
238
accum .append (f"{ inner } , one of (\n " )
210
239
for i , sub_value in enumerate (_get (value , "values" )):
211
240
_comma (accum , i , "|" )
@@ -217,7 +246,9 @@ def _reference_block_valtype(src_path, accum, key, value):
217
246
if _get (value , "arrayOk" ):
218
247
accum .append (f" or array of { _get (value , 'valType' )} s" )
219
248
if _get (value , "min" ) and _get (value , "max" ):
220
- accum .append (f" between or equal to { _get (value , 'min' )} and { _get (value , 'max' )} \n " )
249
+ accum .append (
250
+ f" between or equal to { _get (value , 'min' )} and { _get (value , 'max' )} \n "
251
+ )
221
252
elif _get (value , "min" ):
222
253
accum .append (f" greater than or equal to { _get (value , 'min' )} \n " )
223
254
elif _get (value , "max" ):
@@ -278,7 +309,7 @@ def _reference_block_valtype(src_path, accum, key, value):
278
309
return
279
310
accum .append (f"{ inner } <em>Type:</em> string" )
280
311
if _get (value , "arrayOk" ):
281
- accum .append (f " or array of strings" )
312
+ accum .append (" or array of strings" )
282
313
283
314
else :
284
315
accum .append (f"{ inner } <em>Type:</em> { _get (value , 'valType' )} \n " )
@@ -293,7 +324,6 @@ def _reference_block_valtype(src_path, accum, key, value):
293
324
def _reference_block_dflt (src_path , accum , key , value ):
294
325
"""Handle a default."""
295
326
outer = " " * 16
296
- inner = " " * 20
297
327
if _get (value , "valType" ) == "flaglist" :
298
328
accum .append (
299
329
f"{ outer } <br><em>Default:</em> <code>*{ _get (value , 'dflt' )} *</code>\n "
@@ -307,9 +337,13 @@ def _reference_block_dflt(src_path, accum, key, value):
307
337
accum .append (f"[{ ', ' .join (temp )} ]" )
308
338
elif _get (value , "valType" ) in {"info_array" , "colorlist" }:
309
339
accum .append (f"[{ ', ' .join ([_str (x ) for x in _get (value , 'dflt' )])} ]" )
310
- elif (_get (value , "valType" ) in {"string" , "color" }) or (_get (value , "dflt" ) == "auto" ):
340
+ elif (_get (value , "valType" ) in {"string" , "color" }) or (
341
+ _get (value , "dflt" ) == "auto"
342
+ ):
311
343
accum .append (f"*{ _get (value , 'dflt' )} *" )
312
- elif (_get (value , "valType" ) == "enumerated" ) and (_get (value , "dflt" ) not in {"true" , "false" }):
344
+ elif (_get (value , "valType" ) == "enumerated" ) and (
345
+ _get (value , "dflt" ) not in {"true" , "false" }
346
+ ):
313
347
accum .append (f"*{ _get (value , 'dflt' )} *" )
314
348
else :
315
349
accum .append (_get (value , "dflt" ))
@@ -327,19 +361,21 @@ def _reference_block_array(src_path, accum, key, value):
327
361
accum .append (f"{ inner } { ANNOTATION } \n " )
328
362
329
363
330
- def _reference_block_object (args , src_path , accum , parent_link , parent_path , key , value ):
364
+ def _reference_block_object (
365
+ args , src_path , accum , parent_link , parent_path , key , value
366
+ ):
331
367
"""Handle an object with a recursive call."""
332
- local_parent_link = f"{ parent_link } -{ key } "
333
- local_parent_path = f"{ parent_path } -{ key } "
368
+ parent_path = f"{ parent_path } -{ key } "
334
369
if _get (value , "items" ):
335
370
# This will break if there is ever more than one type of item in items,
336
371
# but for now it's just "shape" and "annotation"
337
372
for item_key , item_value in _get (value , "items" ).items ():
338
373
attributes = item_value
339
- local_parent_link = f"{ parent_link } -{ key } -items-{ item_key } "
340
374
else :
341
375
attributes = value
342
- _reference_block (args , src_path , accum , attributes , parent_link , parent_path , "nested" )
376
+ _reference_block (
377
+ args , src_path , accum , attributes , parent_link , parent_path , "nested"
378
+ )
343
379
344
380
345
381
def _reference_trace (args , schema , src_path , trace_name , trace_data ):
@@ -354,7 +390,9 @@ def _reference_trace(args, schema, src_path, trace_name, trace_data):
354
390
parent_link = trace_name
355
391
parent_path = f"data[type={ trace_name } ]"
356
392
attributes = trace_data ["attributes" ]
357
- _reference_block (args , src_path , accum , attributes , parent_link , parent_path , "data" )
393
+ _reference_block (
394
+ args , src_path , accum , attributes , parent_link , parent_path , "data"
395
+ )
358
396
359
397
return _replace_special ("" .join ([_str (a ) for a in accum ]))
360
398
@@ -377,16 +415,5 @@ def _skip_mustmatch(key, mustmatch):
377
415
return False
378
416
379
417
380
- def _str (val ):
381
- """Hacky string conversion."""
382
- if isinstance (val , str ):
383
- return val
384
- if isinstance (val , bool ):
385
- return str (val ).lower ()
386
- if isinstance (val , int ):
387
- return str (val )
388
- return str (val )
389
-
390
-
391
418
if __name__ == "__main__" :
392
419
main ()
0 commit comments