66from codegen .datatypes import build_datatype_py , write_datatype_py # noqa: F401
77from codegen .compatibility import (
88 write_deprecated_datatypes ,
9- write_graph_objs_graph_objs ,
109 DEPRECATED_DATATYPES ,
1110)
1211from codegen .figure import write_figure_classes
@@ -60,7 +59,7 @@ def preprocess_schema(plotly_schema):
6059matching the structure of `figure.layout` and `traceTemplate` is a dict
6160matching the structure of the trace with type `trace_type` (e.g. 'scatter').
6261Alternatively, this may be specified as an instance of
63- plotly.graph_objs .layout.Template.
62+ plotly.graph_objects .layout.Template.
6463
6564Trace templates are applied cyclically to
6665traces of each type. Container arrays (eg `annotations`) have special
@@ -89,22 +88,22 @@ def make_paths(codedir):
8988 """Make various paths needed for code generation."""
9089
9190 validators_dir = codedir / "validators"
92- graph_objs_dir = codedir / "graph_objs "
91+ graph_objects_dir = codedir / "graph_objects "
9392 graph_objects_path = codedir / "graph_objects" / "__init__.py"
94- return validators_dir , graph_objs_dir , graph_objects_path
93+ return validators_dir , graph_objects_dir , graph_objects_path
9594
9695
9796def perform_codegen (codedir , noformat = False ):
9897 """Generate code."""
9998
10099 # Get paths
101- validators_dir , graph_objs_dir , graph_objects_path = make_paths (codedir )
100+ validators_dir , graph_objects_dir , graph_objects_path = make_paths (codedir )
102101
103102 # Delete prior codegen output
104103 if validators_dir .exists ():
105104 shutil .rmtree (validators_dir )
106- if graph_objs_dir .exists ():
107- shutil .rmtree (graph_objs_dir )
105+ if graph_objects_dir .exists ():
106+ shutil .rmtree (graph_objects_dir )
108107
109108 # Load plotly schema
110109 project_root = codedir .parent
@@ -186,10 +185,10 @@ def perform_codegen(codedir, noformat=False):
186185 write_datatype_py (codedir , node )
187186
188187 # Deprecated
189- # These are deprecated legacy datatypes like graph_objs .Marker
188+ # These are deprecated legacy datatypes like graph_objects .Marker
190189 write_deprecated_datatypes (codedir )
191190
192- # Write figure class to graph_objs
191+ # Write figure class to graph_objects
193192 data_validator = get_data_validator_instance (base_traces_node )
194193 layout_validator = layout_node .get_validator_instance ()
195194 frame_validator = frame_node .get_validator_instance ()
@@ -222,11 +221,6 @@ def perform_codegen(codedir, noformat=False):
222221 f".{ node .name_undercase } "
223222 )
224223
225- # Write plotly/graph_objs/graph_objs.py
226- # This is for backward compatibility. It just imports everything from
227- # graph_objs/__init__.py
228- write_graph_objs_graph_objs (codedir )
229-
230224 # Add Figure and FigureWidget
231225 root_datatype_imports = datatype_rel_class_imports [()]
232226 root_datatype_imports .append ("._figure.Figure" )
@@ -235,71 +229,34 @@ def perform_codegen(codedir, noformat=False):
235229 for dep_clas in DEPRECATED_DATATYPES :
236230 root_datatype_imports .append (f"._deprecations.{ dep_clas } " )
237231
238- optional_figure_widget_import = """
239- if sys.version_info < (3, 7) or TYPE_CHECKING:
240- try:
241- import ipywidgets as _ipywidgets
242- from packaging.version import Version as _Version
243- if _Version(_ipywidgets.__version__) >= _Version("7.0.0"):
244- from ..graph_objs._figurewidget import FigureWidget
245- else:
246- raise ImportError()
247- except Exception:
248- from ..missing_anywidget import FigureWidget
249- else:
250- __all__.append("FigureWidget")
251- orig_getattr = __getattr__
252- def __getattr__(import_name):
253- if import_name == "FigureWidget":
254- try:
255- import ipywidgets
256- from packaging.version import Version
257- if Version(ipywidgets.__version__) >= Version("7.0.0"):
258- from ..graph_objs._figurewidget import FigureWidget
259- return FigureWidget
260- else:
261- raise ImportError()
262- except Exception:
263- from ..missing_anywidget import FigureWidget
264- return FigureWidget
265- else:
266- raise ImportError()
267-
268- return orig_getattr(import_name)
269- """
270232 # __all__
271233 for path_parts , class_names in alls .items ():
272234 if path_parts and class_names :
273- filepath = codedir / "graph_objs "
235+ filepath = codedir / "graph_objects "
274236 filepath = filepath .joinpath (* path_parts ) / "__init__.py"
275237 with open (filepath , "at" ) as f :
276238 f .write (f"\n __all__ = { class_names } " )
277239
278240 # Output datatype __init__.py files
279- graph_objs_pkg = codedir / "graph_objs "
241+ graph_objects_pkg = codedir / "graph_objects "
280242 for path_parts in datatype_rel_class_imports :
281243 rel_classes = sorted (datatype_rel_class_imports [path_parts ])
282244 rel_modules = sorted (datatype_rel_module_imports .get (path_parts , []))
283- if path_parts == ():
284- init_extra = optional_figure_widget_import
285- else :
286- init_extra = ""
287- write_init_py (graph_objs_pkg , path_parts , rel_modules , rel_classes , init_extra )
245+ write_init_py (graph_objects_pkg , path_parts , rel_modules , rel_classes )
288246
289247 # Output graph_objects.py alias
290248 graph_objects_rel_classes = [
291- "..graph_objs ." + rel_path .split ("." )[- 1 ]
249+ "..graph_objects ." + rel_path .split ("." )[- 1 ]
292250 for rel_path in datatype_rel_class_imports [()]
293251 ]
294252 graph_objects_rel_modules = [
295- "..graph_objs ." + rel_module .split ("." )[- 1 ]
253+ "..graph_objects ." + rel_module .split ("." )[- 1 ]
296254 for rel_module in datatype_rel_module_imports [()]
297255 ]
298256
299257 graph_objects_init_source = build_from_imports_py (
300258 graph_objects_rel_modules ,
301259 graph_objects_rel_classes ,
302- init_extra = optional_figure_widget_import ,
303260 )
304261 graph_objects_path = codedir / "graph_objects"
305262 graph_objects_path .mkdir (parents = True , exist_ok = True )
0 commit comments