11import json
22import os
3+ from pathlib import Path
34import shutil
45import sys
56
2728)
2829
2930
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+
3036# Import notes
3137# ------------
3238# Nothing from the plotly/ package should be imported during code
@@ -94,7 +100,7 @@ def make_paths(codedir):
94100 return validators_dir , graph_objects_dir , graph_objs_path
95101
96102
97- def perform_codegen (codedir , noformat = False ):
103+ def perform_codegen (codedir , noformat = False , schema = PLOT_SCHEMA ):
98104 """Generate code."""
99105
100106 # Get paths
@@ -108,8 +114,7 @@ def perform_codegen(codedir, noformat=False):
108114
109115 # Load plotly schema
110116 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 :
113118 plotly_schema = json .load (f )
114119
115120 # Preprocess Schema
@@ -284,7 +289,9 @@ def __getattr__(import_name):
284289 init_extra = optional_figure_widget_import
285290 else :
286291 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+ )
288295
289296 # Output graph_objs.py alias
290297 graph_objs_rel_classes = [
@@ -303,7 +310,7 @@ def __getattr__(import_name):
303310 )
304311 graph_objs_path = codedir / "graph_objs"
305312 graph_objs_path .mkdir (parents = True , exist_ok = True )
306- graph_objs_path /= "__init__.py"
313+ graph_objs_path /= "__init__.py"
307314 with open (graph_objs_path , "wt" ) as f :
308315 f .write ("# ruff: noqa: F401\n " )
309316 f .write (graph_objs_init_source )
0 commit comments