20
20
sys .path .insert (0 , str (Path (__file__ ).parent .parent ))
21
21
22
22
try :
23
- import plotly .graph_objs as graph_objs
23
+ import plotly .graph_objects as graph_objs
24
24
except ImportError as e :
25
- print (f"Error importing plotly.graph_objs : { e } " )
25
+ print (f"Error importing plotly.graph_objects : { e } " )
26
26
print ("Make sure you're running this script from the plotly.py repository root" )
27
27
sys .exit (1 )
28
28
29
29
30
30
class GraphObjectsInspector :
31
- """Inspects plotly.graph_objs to discover all classes and packages."""
31
+ """Inspects plotly.graph_objects to discover all classes and packages."""
32
32
33
33
def __init__ (self ):
34
34
self .classes : Dict [str , Any ] = {}
@@ -88,35 +88,43 @@ def inspect_module(self, module, prefix: str = "") -> None:
88
88
89
89
try :
90
90
attr = getattr (module , attr_name )
91
- full_name = f"{ module_name } .{ attr_name } " if prefix else f"plotly.graph_objs .{ attr_name } "
91
+ full_name = f"{ module_name } .{ attr_name } " if prefix else f"plotly.graph_objects .{ attr_name } "
92
92
93
93
if self .is_class (attr ):
94
94
# Use the public API path instead of internal module path
95
- public_full_name = f"{ module_name } .{ attr_name } "
95
+ # Convert graph_objs to graph_objects in the module path
96
+ if module_name .startswith ("plotly.graph_objs" ):
97
+ public_full_name = module_name .replace ("plotly.graph_objs" , "plotly.graph_objects" ) + f".{ attr_name } "
98
+ else :
99
+ public_full_name = f"{ module_name } .{ attr_name } "
96
100
self .classes [public_full_name ] = attr
97
101
print (f" Found class: { public_full_name } " )
98
102
99
103
elif self .is_package (attr ):
100
104
# Check if it's actually a submodule of the current module
101
105
if hasattr (attr , '__file__' ) and attr .__file__ :
102
- self .packages [full_name ] = attr
103
- self .module_paths [full_name ] = self .get_module_path (attr )
104
- print (f" Found package: { full_name } " )
106
+ # Convert graph_objs to graph_objects in package names too
107
+ public_package_name = full_name
108
+ if full_name .startswith ("plotly.graph_objs" ):
109
+ public_package_name = full_name .replace ("plotly.graph_objs" , "plotly.graph_objects" )
110
+ self .packages [public_package_name ] = attr
111
+ self .module_paths [public_package_name ] = self .get_module_path (attr )
112
+ print (f" Found package: { public_package_name } " )
105
113
106
114
# Recursively inspect the package
107
- self .inspect_module (attr , full_name )
115
+ self .inspect_module (attr , public_package_name )
108
116
109
117
except Exception as e :
110
118
print (f" Error inspecting { attr_name } : { e } " )
111
119
continue
112
120
113
121
def discover_structure (self ) -> None :
114
- """Discover the complete structure of plotly.graph_objs ."""
115
- print ("Discovering plotly.graph_objs structure..." )
122
+ """Discover the complete structure of plotly.graph_objects ."""
123
+ print ("Discovering plotly.graph_objects structure..." )
116
124
117
- # Add the main plotly.graph_objs module as a package
118
- self .packages ["plotly.graph_objs " ] = graph_objs
119
- self .module_paths ["plotly.graph_objs " ] = self .get_module_path (graph_objs )
125
+ # Add the main plotly.graph_objects module as a package
126
+ self .packages ["plotly.graph_objects " ] = graph_objs
127
+ self .module_paths ["plotly.graph_objects " ] = self .get_module_path (graph_objs )
120
128
121
129
self .inspect_module (graph_objs )
122
130
print (f"\n Discovery complete:" )
@@ -143,25 +151,25 @@ def clean_output_dir(self) -> None:
143
151
def generate_class_page (self , class_name : str , class_obj : Any ) -> Path :
144
152
"""Generate a documentation page for a class."""
145
153
# Convert module path to file path
146
- # e.g., "plotly.graph_objs .Bar" -> "Bar.md"
147
- # e.g., "plotly.graph_objs .bar.Marker" -> "bar-package/Marker.md"
148
- # e.g., "plotly.graph_objs .bar.hoverlabel.Font" -> "bar/hoverlabel-package/Font.md"
154
+ # e.g., "plotly.graph_objects .Bar" -> "Bar.md"
155
+ # e.g., "plotly.graph_objects .bar.Marker" -> "bar-package/Marker.md"
156
+ # e.g., "plotly.graph_objects .bar.hoverlabel.Font" -> "bar/hoverlabel-package/Font.md"
149
157
150
158
parts = class_name .split ('.' )
151
- if len (parts ) > 2 : # plotly.graph_objs .something
152
- # Remove "plotly.graph_objs " prefix
159
+ if len (parts ) > 2 : # plotly.graph_objects .something
160
+ # Remove "plotly.graph_objects " prefix
153
161
relative_parts = parts [2 :]
154
162
if len (relative_parts ) == 1 :
155
- # Top-level class: plotly.graph_objs .Bar -> Bar.md
163
+ # Top-level class: plotly.graph_objects .Bar -> Bar.md
156
164
file_path = self .output_dir / f"{ parts [- 1 ]} .md"
157
165
else :
158
166
# Classes inside packages
159
167
parent_parts = relative_parts [:- 1 ]
160
168
if len (parent_parts ) == 1 :
161
- # e.g., plotly.graph_objs .bar.Marker -> bar-package/Marker.md
169
+ # e.g., plotly.graph_objects .bar.Marker -> bar-package/Marker.md
162
170
parent_dir = self .output_dir / f"{ parent_parts [0 ]} -package"
163
171
else :
164
- # e.g., plotly.graph_objs .bar.hoverlabel.Font -> bar-package/hoverlabel-package/Font.md
172
+ # e.g., plotly.graph_objects .bar.hoverlabel.Font -> bar-package/hoverlabel-package/Font.md
165
173
parent_dirs_with_suffix = [part + '-package' for part in parent_parts [:- 1 ]]
166
174
parent_dir = self .output_dir / Path (* parent_dirs_with_suffix ) / f"{ parent_parts [- 1 ]} -package"
167
175
file_path = parent_dir / f"{ parts [- 1 ]} .md"
@@ -201,7 +209,7 @@ def generate_package_index(self, package_name: str, package_obj: Any) -> Path:
201
209
"""Generate an index page for a package."""
202
210
# Convert module path to file path
203
211
parts = package_name .split ('.' )
204
- if len (parts ) > 2 : # plotly.graph_objs .something
212
+ if len (parts ) > 2 : # plotly.graph_objects .something
205
213
relative_parts = parts [2 :]
206
214
# Add -package suffix to avoid conflicts with class names
207
215
package_name_with_suffix = f"{ relative_parts [- 1 ]} -package"
@@ -213,7 +221,7 @@ def generate_package_index(self, package_name: str, package_obj: Any) -> Path:
213
221
# For top-level packages
214
222
file_path = self .output_dir / package_name_with_suffix / "index.md"
215
223
else :
216
- # This is the main plotly.graph_objs package
224
+ # This is the main plotly.graph_objects package
217
225
file_path = self .output_dir / "index.md"
218
226
219
227
# Create directory if needed
@@ -269,34 +277,34 @@ def generate_package_index(self, package_name: str, package_obj: Any) -> Path:
269
277
return file_path
270
278
271
279
def generate_main_index (self ) -> Path :
272
- """Generate the main index page for plotly.graph_objs with both classes and packages."""
280
+ """Generate the main index page for plotly.graph_objects with both classes and packages."""
273
281
file_path = self .output_dir / "index.md"
274
282
275
- # Get top-level classes (those directly in plotly.graph_objs )
283
+ # Get top-level classes (those directly in plotly.graph_objects )
276
284
top_level_classes = []
277
285
for class_name , class_obj in self .inspector .classes .items ():
278
- if class_name .startswith ("plotly.graph_objs ." ) and class_name .count ("." ) == 2 :
279
- # This is a top-level class like plotly.graph_objs .Bar
286
+ if class_name .startswith ("plotly.graph_objects ." ) and class_name .count ("." ) == 2 :
287
+ # This is a top-level class like plotly.graph_objects .Bar
280
288
short_name = class_name .split ("." )[- 1 ]
281
289
top_level_classes .append ((short_name , class_name ))
282
290
283
- # Get top-level packages (those directly in plotly.graph_objs )
291
+ # Get top-level packages (those directly in plotly.graph_objects )
284
292
top_level_packages = []
285
293
for package_name , package_obj in self .inspector .packages .items ():
286
- if package_name .startswith ("plotly.graph_objs ." ) and package_name .count ("." ) == 2 :
287
- # This is a top-level package like plotly.graph_objs .bar
294
+ if package_name .startswith ("plotly.graph_objects ." ) and package_name .count ("." ) == 2 :
295
+ # This is a top-level package like plotly.graph_objects .bar
288
296
short_name = package_name .split ("." )[- 1 ]
289
297
top_level_packages .append ((short_name , package_name ))
290
- elif not package_name .startswith ("plotly.graph_objs ." ) and "." not in package_name :
298
+ elif not package_name .startswith ("plotly.graph_objects ." ) and "." not in package_name :
291
299
# This is a top-level package like "bar" (without the full path)
292
- top_level_packages .append ((package_name , f"plotly.graph_objs .{ package_name } " ))
300
+ top_level_packages .append ((package_name , f"plotly.graph_objects .{ package_name } " ))
293
301
294
302
# Sort both lists
295
303
top_level_classes .sort (key = lambda x : x [0 ])
296
304
top_level_packages .sort (key = lambda x : x [0 ])
297
305
298
306
# Generate content
299
- content = "# plotly.graph_objs \n \n "
307
+ content = "# plotly.graph_objects \n \n "
300
308
content += "The main package containing all Plotly graph objects, traces, and layout components.\n \n "
301
309
302
310
if top_level_classes :
@@ -319,8 +327,8 @@ def generate_main_index(self) -> Path:
319
327
320
328
# Check if any deprecated classes exist by testing a known deprecated class
321
329
try :
322
- angular_axis_obj = self .inspector .classes .get ("plotly.graph_objs .AngularAxis" )
323
- if angular_axis_obj and self .inspector .is_deprecated_class ("plotly.graph_objs .AngularAxis" , angular_axis_obj ):
330
+ angular_axis_obj = self .inspector .classes .get ("plotly.graph_objects .AngularAxis" )
331
+ if angular_axis_obj and self .inspector .is_deprecated_class ("plotly.graph_objects .AngularAxis" , angular_axis_obj ):
324
332
content += "## Notes\n \n "
325
333
content += "⚠️ **Deprecated Classes**: Some classes marked as deprecated are legacy classes that have been replaced with more specific implementations in submodules. Please refer to the specific implementation in the appropriate submodule for current usage.\n "
326
334
except Exception :
@@ -354,7 +362,7 @@ def generate_all_documentation(self, clean: bool = False) -> None:
354
362
print ("\n Generating package index pages..." )
355
363
356
364
# First, generate index pages for all packages except the main one
357
- main_package_name = "plotly.graph_objs "
365
+ main_package_name = "plotly.graph_objects "
358
366
for package_name , package_obj in self .inspector .packages .items ():
359
367
if package_name != main_package_name : # Skip the main package for now
360
368
try :
@@ -363,7 +371,7 @@ def generate_all_documentation(self, clean: bool = False) -> None:
363
371
except Exception as e :
364
372
print (f" Error generating { package_name } : { e } " )
365
373
366
- # Finally, generate the main index for plotly.graph_objs (this should be last)
374
+ # Finally, generate the main index for plotly.graph_objects (this should be last)
367
375
try :
368
376
file_path = self .generate_main_index ()
369
377
print (f" Generated: { file_path .relative_to (self .output_dir )} " )
0 commit comments