|
36 | 36 | pio.templates.default = 'none'
|
37 | 37 | pio.kaleido.scope.plotlyjs = os.path.join(root, 'build', 'plotly.js')
|
38 | 38 |
|
39 |
| -_credentials = open(os.path.join(root, 'build', 'credentials.json'), 'r') |
40 |
| -pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN'] |
41 |
| -_credentials.close() |
42 |
| - |
| 39 | +with open(os.path.join(root, 'build', 'credentials.json'), 'r') as _credentials: |
| 40 | + pio.kaleido.scope.mapbox_access_token = json.load(_credentials)['MAPBOX_ACCESS_TOKEN'] |
43 | 41 | ALL_MOCKS = [os.path.splitext(a)[0] for a in os.listdir(dirIn) if a.endswith('.json')]
|
44 | 42 | ALL_MOCKS.sort()
|
45 | 43 |
|
46 |
| -if len(args) > 0 : |
47 |
| - allNames = [a for a in args if a in ALL_MOCKS] |
48 |
| -else : |
49 |
| - allNames = ALL_MOCKS |
50 |
| - |
| 44 | +allNames = [a for a in args if a in ALL_MOCKS] if len(args) > 0 else ALL_MOCKS |
51 | 45 | # gl2d pointcloud and other non-regl gl2d mock(s)
|
52 | 46 | # must be tested in certain order to work on CircleCI;
|
53 | 47 | #
|
|
81 | 75 | ]
|
82 | 76 | allNames = [a for a in allNames if a not in blacklist]
|
83 | 77 |
|
84 |
| -if len(allNames) == 0 : |
| 78 | +if not allNames: |
85 | 79 | print('error: Nothing to create!')
|
86 | 80 | sys.exit(1)
|
87 | 81 |
|
88 | 82 | failed = []
|
89 |
| -for name in allNames : |
| 83 | +MAX_RETRY = 2 # 1 means retry once |
| 84 | +for name in allNames: |
90 | 85 | outName = name
|
91 |
| - if mathjax_version == 3 : |
92 |
| - outName = 'mathjax3___' + name |
| 86 | + if mathjax_version == 3: |
| 87 | + outName = f'mathjax3___{name}' |
93 | 88 |
|
94 | 89 | print(outName)
|
95 | 90 |
|
96 | 91 | created = False
|
97 | 92 |
|
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 : |
| 93 | + for attempt in range(MAX_RETRY + 1): |
| 94 | + with open(os.path.join(dirIn, f'{name}.json'), 'r') as _in: |
101 | 95 | fig = json.load(_in)
|
102 | 96 |
|
103 | 97 | width = 700
|
|
110 | 104 | if 'height' in layout :
|
111 | 105 | height = layout['height']
|
112 | 106 |
|
113 |
| - try : |
| 107 | + try: |
114 | 108 | pio.write_image(
|
115 | 109 | fig=fig,
|
116 |
| - file=os.path.join(dirOut, outName + '.png'), |
| 110 | + file=os.path.join(dirOut, f'{outName}.png'), |
117 | 111 | width=width,
|
118 | 112 | height=height,
|
119 |
| - validate=False |
| 113 | + validate=False, |
120 | 114 | )
|
| 115 | + |
121 | 116 | created = True
|
122 | 117 | except Exception as e :
|
123 | 118 | print(e)
|
|
128 | 123 |
|
129 | 124 | if(created) : break
|
130 | 125 |
|
131 |
| -if len(failed) > 0 : |
| 126 | +if failed: |
132 | 127 | print('Failed at :')
|
133 | 128 | print(failed)
|
134 | 129 | sys.exit(1)
|
0 commit comments