1
1
import json
2
2
import os
3
+ from pathlib import Path
3
4
import shutil
4
5
import sys
5
6
27
28
)
28
29
29
30
31
+ PROJECT_ROOT = Path (__file__ ).parent .parent .parent
32
+ PLOT_SCHEMA_RELATIVE = Path ("resources" ) / "plot-schema.json"
33
+ PLOT_SCHEMA = PROJECT_ROOT / PLOT_SCHEMA_RELATIVE
34
+
35
+
30
36
# Import notes
31
37
# ------------
32
38
# Nothing from the plotly/ package should be imported during code
@@ -94,7 +100,7 @@ def make_paths(codedir):
94
100
return validators_dir , graph_objects_dir , graph_objs_path
95
101
96
102
97
- def perform_codegen (codedir , noformat = False ):
103
+ def perform_codegen (codedir , noformat = False , schema = PLOT_SCHEMA ):
98
104
"""Generate code."""
99
105
100
106
# Get paths
@@ -108,8 +114,7 @@ def perform_codegen(codedir, noformat=False):
108
114
109
115
# Load plotly schema
110
116
project_root = codedir .parent
111
- plot_schema_path = project_root / "resources" / "plot-schema.json"
112
- with open (plot_schema_path , "r" ) as f :
117
+ with open (schema , "r" ) as f :
113
118
plotly_schema = json .load (f )
114
119
115
120
# Preprocess Schema
@@ -284,7 +289,9 @@ def __getattr__(import_name):
284
289
init_extra = optional_figure_widget_import
285
290
else :
286
291
init_extra = ""
287
- write_init_py (graph_objects_pkg , path_parts , rel_modules , rel_classes , init_extra )
292
+ write_init_py (
293
+ graph_objects_pkg , path_parts , rel_modules , rel_classes , init_extra
294
+ )
288
295
289
296
# Output graph_objs.py alias
290
297
graph_objs_rel_classes = [
@@ -303,7 +310,7 @@ def __getattr__(import_name):
303
310
)
304
311
graph_objs_path = codedir / "graph_objs"
305
312
graph_objs_path .mkdir (parents = True , exist_ok = True )
306
- graph_objs_path /= "__init__.py"
313
+ graph_objs_path /= "__init__.py"
307
314
with open (graph_objs_path , "wt" ) as f :
308
315
f .write ("# ruff: noqa: F401\n " )
309
316
f .write (graph_objs_init_source )
0 commit comments