Generate code (and possibly reformat).
(outdir, noformat=False)
| 109 | |
| 110 | |
| 111 | def perform_codegen(outdir, noformat=False): |
| 112 | """Generate code (and possibly reformat).""" |
| 113 | |
| 114 | # Get paths |
| 115 | validators_dir, graph_objs_dir, graph_objects_path = make_paths(outdir) |
| 116 | |
| 117 | # Delete prior codegen output |
| 118 | if opath.exists(validators_dir): |
| 119 | shutil.rmtree(validators_dir) |
| 120 | if opath.exists(graph_objs_dir): |
| 121 | shutil.rmtree(graph_objs_dir) |
| 122 | |
| 123 | # Load plotly schema |
| 124 | project_root = opath.dirname(outdir) |
| 125 | plot_schema_path = opath.join( |
| 126 | project_root, "codegen", "resources", "plot-schema.json" |
| 127 | ) |
| 128 | |
| 129 | with open(plot_schema_path, "r") as f: |
| 130 | plotly_schema = json.load(f) |
| 131 | |
| 132 | # Preprocess Schema |
| 133 | preprocess_schema(plotly_schema) |
| 134 | |
| 135 | # Build node lists |
| 136 | |
| 137 | # TraceNode |
| 138 | base_traces_node = TraceNode(plotly_schema) |
| 139 | all_trace_nodes = PlotlyNode.get_all_datatype_nodes(plotly_schema, TraceNode) |
| 140 | |
| 141 | # LayoutNode |
| 142 | compound_layout_nodes = PlotlyNode.get_all_compound_datatype_nodes( |
| 143 | plotly_schema, LayoutNode |
| 144 | ) |
| 145 | layout_node = compound_layout_nodes[0] |
| 146 | all_layout_nodes = PlotlyNode.get_all_datatype_nodes(plotly_schema, LayoutNode) |
| 147 | |
| 148 | subplot_nodes = [ |
| 149 | node |
| 150 | for node in layout_node.child_compound_datatypes |
| 151 | if node.node_data.get("_isSubplotObj", False) |
| 152 | ] |
| 153 | |
| 154 | layout_array_nodes = [ |
| 155 | node |
| 156 | for node in layout_node.child_compound_datatypes |
| 157 | if node.is_array_element and node.has_child("xref") and node.has_child("yref") |
| 158 | ] |
| 159 | |
| 160 | # FrameNode |
| 161 | compound_frame_nodes = PlotlyNode.get_all_compound_datatype_nodes( |
| 162 | plotly_schema, FrameNode |
| 163 | ) |
| 164 | frame_node = compound_frame_nodes[0] |
| 165 | all_frame_nodes = PlotlyNode.get_all_datatype_nodes(plotly_schema, FrameNode) |
| 166 | |
| 167 | # All nodes |
| 168 | all_datatype_nodes = all_trace_nodes + all_layout_nodes + all_frame_nodes |
no test coverage detected