Skip to content

Commit 12e4ffe

Browse files
committed
Add __all__ statements to graph_objs/ hierarchy, and the graph_objects.py alias
1 parent 4a30dc6 commit 12e4ffe

File tree

305 files changed

+48744
-47106
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

305 files changed

+48744
-47106
lines changed

Diff for: packages/python/plotly/codegen/__init__.py

+41-13
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,22 @@ def perform_codegen():
176176
# ### Data (traces) validator ###
177177
write_data_validator_py(outdir, base_traces_node)
178178

179+
# Alls
180+
# ----
181+
alls = {}
182+
179183
# Write out datatypes
180184
# -------------------
181-
# ### Layout ###
182-
for node in compound_layout_nodes:
183-
write_datatype_py(outdir, node)
184-
185-
# ### Trace ###
186-
for node in compound_trace_nodes:
187-
write_datatype_py(outdir, node)
188-
189-
# ### Frames ###
190-
for node in compound_frame_nodes:
185+
for node in all_compound_nodes:
191186
write_datatype_py(outdir, node)
187+
alls.setdefault(node.path_parts, [])
188+
alls[node.path_parts].extend(
189+
c.name_datatype_class for c in node.child_compound_datatypes
190+
)
191+
if node.parent_path_parts == ():
192+
# Add top-level classes to alls
193+
alls.setdefault((), [])
194+
alls[node.parent_path_parts].append(node.name_datatype_class)
192195

193196
# ### Deprecated ###
194197
# These are deprecated legacy datatypes like graph_objs.Marker
@@ -222,6 +225,7 @@ def perform_codegen():
222225
path_to_datatype_import_info.setdefault(key, []).append(
223226
(f"plotly.graph_objs{node.parent_dotpath_str}", node.name_undercase)
224227
)
228+
alls[node.parent_path_parts].append(node.name_undercase)
225229

226230
# ### Write plotly/graph_objs/graph_objs.py ###
227231
# This if for backward compatibility. It just imports everything from
@@ -231,31 +235,55 @@ def perform_codegen():
231235
# ### Add Figure and FigureWidget ###
232236
root_datatype_imports = path_to_datatype_import_info[()]
233237
root_datatype_imports.append(("._figure", "Figure"))
238+
alls[()].append("Figure")
234239

235-
optional_figure_widget_import = """
240+
# ### Add deprecations ###
241+
root_datatype_imports.append(("._deprecations", DEPRECATED_DATATYPES.keys()))
242+
alls[()].extend(DEPRECATED_DATATYPES.keys())
243+
244+
# Sort alls
245+
for k, v in alls.items():
246+
alls[k] = list(sorted(v))
247+
248+
optional_figure_widget_import = f"""
249+
__all__ = {alls[()]}
236250
try:
237251
import ipywidgets
238252
from distutils.version import LooseVersion
239253
if LooseVersion(ipywidgets.__version__) >= LooseVersion('7.0.0'):
240254
from ._figurewidget import FigureWidget
241255
del LooseVersion
242256
del ipywidgets
257+
__all__.append("FigureWidget")
243258
except ImportError:
244259
pass
245260
"""
246261
root_datatype_imports.append(optional_figure_widget_import)
247262

248-
# ### Add deprecations ###
249-
root_datatype_imports.append(("._deprecations", DEPRECATED_DATATYPES.keys()))
263+
# ### __all__ ###
264+
for path_parts, class_names in alls.items():
265+
if path_parts and class_names:
266+
filepath = opath.join(outdir, "graph_objs", *path_parts, "__init__.py")
267+
with open(filepath, "at") as f:
268+
f.write(f"\n__all__ = {class_names}")
250269

251270
# ### Output datatype __init__.py files ###
252271
graph_objs_pkg = opath.join(outdir, "graph_objs")
253272
for path_parts, import_pairs in path_to_datatype_import_info.items():
254273
write_init_py(graph_objs_pkg, path_parts, import_pairs)
255274

275+
# ### Output graph_objects.py alias
276+
graph_objects_path = opath.join(outdir, "graph_objects.py")
277+
with open(graph_objects_path, "wt") as f:
278+
f.write(f"""\
279+
from __future__ import absolute_import
280+
from plotly.graph_objs import *
281+
__all__ = {alls[()]}""")
282+
256283
# ### Run black code formatter on output directories ###
257284
subprocess.call(["black", "--target-version=py27", validators_pkgdir])
258285
subprocess.call(["black", "--target-version=py27", graph_objs_pkgdir])
286+
subprocess.call(["black", "--target-version=py27", graph_objects_path])
259287

260288

261289
if __name__ == "__main__":

Diff for: packages/python/plotly/plotly/graph_objects.py

+122
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,124 @@
11
from __future__ import absolute_import
22
from plotly.graph_objs import *
3+
4+
__all__ = [
5+
"AngularAxis",
6+
"Annotation",
7+
"Annotations",
8+
"Area",
9+
"Bar",
10+
"Barpolar",
11+
"Box",
12+
"Candlestick",
13+
"Carpet",
14+
"Choropleth",
15+
"Choroplethmapbox",
16+
"ColorBar",
17+
"Cone",
18+
"Contour",
19+
"Contourcarpet",
20+
"Contours",
21+
"Data",
22+
"Densitymapbox",
23+
"ErrorX",
24+
"ErrorY",
25+
"ErrorZ",
26+
"Figure",
27+
"Font",
28+
"Frame",
29+
"Frames",
30+
"Funnel",
31+
"Funnelarea",
32+
"Heatmap",
33+
"Heatmapgl",
34+
"Histogram",
35+
"Histogram2d",
36+
"Histogram2dContour",
37+
"Histogram2dcontour",
38+
"Indicator",
39+
"Isosurface",
40+
"Layout",
41+
"Legend",
42+
"Line",
43+
"Margin",
44+
"Marker",
45+
"Mesh3d",
46+
"Ohlc",
47+
"Parcats",
48+
"Parcoords",
49+
"Pie",
50+
"Pointcloud",
51+
"RadialAxis",
52+
"Sankey",
53+
"Scatter",
54+
"Scatter3d",
55+
"Scattercarpet",
56+
"Scattergeo",
57+
"Scattergl",
58+
"Scattermapbox",
59+
"Scatterpolar",
60+
"Scatterpolargl",
61+
"Scatterternary",
62+
"Scene",
63+
"Splom",
64+
"Stream",
65+
"Streamtube",
66+
"Sunburst",
67+
"Surface",
68+
"Table",
69+
"Trace",
70+
"Violin",
71+
"Volume",
72+
"Waterfall",
73+
"XAxis",
74+
"XBins",
75+
"YAxis",
76+
"YBins",
77+
"ZAxis",
78+
"area",
79+
"bar",
80+
"barpolar",
81+
"box",
82+
"candlestick",
83+
"carpet",
84+
"choropleth",
85+
"choroplethmapbox",
86+
"cone",
87+
"contour",
88+
"contourcarpet",
89+
"densitymapbox",
90+
"funnel",
91+
"funnelarea",
92+
"heatmap",
93+
"heatmapgl",
94+
"histogram",
95+
"histogram2d",
96+
"histogram2dcontour",
97+
"indicator",
98+
"isosurface",
99+
"layout",
100+
"mesh3d",
101+
"ohlc",
102+
"parcats",
103+
"parcoords",
104+
"pie",
105+
"pointcloud",
106+
"sankey",
107+
"scatter",
108+
"scatter3d",
109+
"scattercarpet",
110+
"scattergeo",
111+
"scattergl",
112+
"scattermapbox",
113+
"scatterpolar",
114+
"scatterpolargl",
115+
"scatterternary",
116+
"splom",
117+
"streamtube",
118+
"sunburst",
119+
"surface",
120+
"table",
121+
"violin",
122+
"volume",
123+
"waterfall",
124+
]

0 commit comments

Comments
 (0)