Skip to content

Commit 4b3017b

Browse files
committed
Update generate_graph_objects_docs.py
1 parent 3ccc598 commit 4b3017b

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

scripts/generate_graph_objects_docs.py

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
sys.path.insert(0, str(Path(__file__).parent.parent))
2121

2222
try:
23-
import plotly.graph_objs as graph_objs
23+
import plotly.graph_objects as graph_objs
2424
except ImportError as e:
25-
print(f"Error importing plotly.graph_objs: {e}")
25+
print(f"Error importing plotly.graph_objects: {e}")
2626
print("Make sure you're running this script from the plotly.py repository root")
2727
sys.exit(1)
2828

2929

3030
class GraphObjectsInspector:
31-
"""Inspects plotly.graph_objs to discover all classes and packages."""
31+
"""Inspects plotly.graph_objects to discover all classes and packages."""
3232

3333
def __init__(self):
3434
self.classes: Dict[str, Any] = {}
@@ -88,35 +88,43 @@ def inspect_module(self, module, prefix: str = "") -> None:
8888

8989
try:
9090
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}"
9292

9393
if self.is_class(attr):
9494
# 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}"
96100
self.classes[public_full_name] = attr
97101
print(f" Found class: {public_full_name}")
98102

99103
elif self.is_package(attr):
100104
# Check if it's actually a submodule of the current module
101105
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}")
105113

106114
# Recursively inspect the package
107-
self.inspect_module(attr, full_name)
115+
self.inspect_module(attr, public_package_name)
108116

109117
except Exception as e:
110118
print(f" Error inspecting {attr_name}: {e}")
111119
continue
112120

113121
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...")
116124

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)
120128

121129
self.inspect_module(graph_objs)
122130
print(f"\nDiscovery complete:")
@@ -143,25 +151,25 @@ def clean_output_dir(self) -> None:
143151
def generate_class_page(self, class_name: str, class_obj: Any) -> Path:
144152
"""Generate a documentation page for a class."""
145153
# 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"
149157

150158
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
153161
relative_parts = parts[2:]
154162
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
156164
file_path = self.output_dir / f"{parts[-1]}.md"
157165
else:
158166
# Classes inside packages
159167
parent_parts = relative_parts[:-1]
160168
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
162170
parent_dir = self.output_dir / f"{parent_parts[0]}-package"
163171
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
165173
parent_dirs_with_suffix = [part + '-package' for part in parent_parts[:-1]]
166174
parent_dir = self.output_dir / Path(*parent_dirs_with_suffix) / f"{parent_parts[-1]}-package"
167175
file_path = parent_dir / f"{parts[-1]}.md"
@@ -201,7 +209,7 @@ def generate_package_index(self, package_name: str, package_obj: Any) -> Path:
201209
"""Generate an index page for a package."""
202210
# Convert module path to file path
203211
parts = package_name.split('.')
204-
if len(parts) > 2: # plotly.graph_objs.something
212+
if len(parts) > 2: # plotly.graph_objects.something
205213
relative_parts = parts[2:]
206214
# Add -package suffix to avoid conflicts with class names
207215
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:
213221
# For top-level packages
214222
file_path = self.output_dir / package_name_with_suffix / "index.md"
215223
else:
216-
# This is the main plotly.graph_objs package
224+
# This is the main plotly.graph_objects package
217225
file_path = self.output_dir / "index.md"
218226

219227
# Create directory if needed
@@ -269,34 +277,34 @@ def generate_package_index(self, package_name: str, package_obj: Any) -> Path:
269277
return file_path
270278

271279
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."""
273281
file_path = self.output_dir / "index.md"
274282

275-
# Get top-level classes (those directly in plotly.graph_objs)
283+
# Get top-level classes (those directly in plotly.graph_objects)
276284
top_level_classes = []
277285
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
280288
short_name = class_name.split(".")[-1]
281289
top_level_classes.append((short_name, class_name))
282290

283-
# Get top-level packages (those directly in plotly.graph_objs)
291+
# Get top-level packages (those directly in plotly.graph_objects)
284292
top_level_packages = []
285293
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
288296
short_name = package_name.split(".")[-1]
289297
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:
291299
# 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}"))
293301

294302
# Sort both lists
295303
top_level_classes.sort(key=lambda x: x[0])
296304
top_level_packages.sort(key=lambda x: x[0])
297305

298306
# Generate content
299-
content = "# plotly.graph_objs\n\n"
307+
content = "# plotly.graph_objects\n\n"
300308
content += "The main package containing all Plotly graph objects, traces, and layout components.\n\n"
301309

302310
if top_level_classes:
@@ -319,8 +327,8 @@ def generate_main_index(self) -> Path:
319327

320328
# Check if any deprecated classes exist by testing a known deprecated class
321329
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):
324332
content += "## Notes\n\n"
325333
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"
326334
except Exception:
@@ -354,7 +362,7 @@ def generate_all_documentation(self, clean: bool = False) -> None:
354362
print("\nGenerating package index pages...")
355363

356364
# 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"
358366
for package_name, package_obj in self.inspector.packages.items():
359367
if package_name != main_package_name: # Skip the main package for now
360368
try:
@@ -363,7 +371,7 @@ def generate_all_documentation(self, clean: bool = False) -> None:
363371
except Exception as e:
364372
print(f" Error generating {package_name}: {e}")
365373

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)
367375
try:
368376
file_path = self.generate_main_index()
369377
print(f" Generated: {file_path.relative_to(self.output_dir)}")

0 commit comments

Comments
 (0)