Skip to content

Commit 3f7ba75

Browse files
committed
feat: merging code generator work with latest changes on master
1. Modify `commands.py` to run code generation. 2. Regenerate all code. Notes: The generated code is reformatted once again: this slightly increases size but makes it more readable. There is one flaky test: `tests/test_plotly_utils/validators/test_colorscale_validator.py::test_acceptance_named[Inferno_r]` It fails when the entire test suite is run but does *not* fail when only `test_colorscale_validator.py` is run (using Python 3.11.9).
1 parent 556dd53 commit 3f7ba75

File tree

14,842 files changed

+242921
-208420
lines changed

Some content is hidden

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

14,842 files changed

+242921
-208420
lines changed

commands.py

+37-29
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1+
from distutils import log
2+
import json
13
import os
2-
import sys
3-
import time
44
import platform
5-
import json
65
import shutil
7-
86
from subprocess import check_call
9-
from distutils import log
7+
import sys
8+
import time
109

11-
project_root = os.path.dirname(os.path.abspath(__file__))
12-
node_root = os.path.join(project_root, "js")
13-
is_repo = os.path.exists(os.path.join(project_root, ".git"))
14-
node_modules = os.path.join(node_root, "node_modules")
15-
targets = [
16-
os.path.join(project_root, "plotly", "package_data", "widgetbundle.js"),
10+
USAGE = "usage: python commands.py [updateplotlyjsdev | updateplotlyjs | codegen]"
11+
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
12+
NODE_ROOT = os.path.join(PROJECT_ROOT, "js")
13+
NODE_MODULES = os.path.join(NODE_ROOT, "node_modules")
14+
TARGETS = [
15+
os.path.join(PROJECT_ROOT, "plotly", "package_data", "widgetbundle.js"),
1716
]
1817

19-
npm_path = os.pathsep.join(
18+
NPM_PATH = os.pathsep.join(
2019
[
21-
os.path.join(node_root, "node_modules", ".bin"),
20+
os.path.join(NODE_ROOT, "node_modules", ".bin"),
2221
os.environ.get("PATH", os.defpath),
2322
]
2423
)
2524

2625
# Load plotly.js version from js/package.json
2726
def plotly_js_version():
28-
path = os.path.join(project_root, "js", "package.json")
27+
path = os.path.join(PROJECT_ROOT, "js", "package.json")
2928
with open(path, "rt") as f:
3029
package_json = json.load(f)
3130
version = package_json["dependencies"]["plotly.js"]
@@ -57,33 +56,33 @@ def install_js_deps(local):
5756
)
5857

5958
env = os.environ.copy()
60-
env["PATH"] = npm_path
59+
env["PATH"] = NPM_PATH
6160

6261
if has_npm:
6362
log.info("Installing build dependencies with npm. This may take a while...")
6463
check_call(
6564
[npmName, "install"],
66-
cwd=node_root,
65+
cwd=NODE_ROOT,
6766
stdout=sys.stdout,
6867
stderr=sys.stderr,
6968
)
7069
if local is not None:
7170
plotly_archive = os.path.join(local, "plotly.js.tgz")
7271
check_call(
7372
[npmName, "install", plotly_archive],
74-
cwd=node_root,
73+
cwd=NODE_ROOT,
7574
stdout=sys.stdout,
7675
stderr=sys.stderr,
7776
)
7877
check_call(
7978
[npmName, "run", "build"],
80-
cwd=node_root,
79+
cwd=NODE_ROOT,
8180
stdout=sys.stdout,
8281
stderr=sys.stderr,
8382
)
84-
os.utime(node_modules, None)
83+
os.utime(NODE_MODULES, None)
8584

86-
for t in targets:
85+
for t in TARGETS:
8786
if not os.path.exists(t):
8887
msg = "Missing file: %s" % t
8988
raise ValueError(msg)
@@ -100,7 +99,7 @@ def run_codegen():
10099

101100

102101
def overwrite_schema_local(uri):
103-
path = os.path.join(project_root, "codegen", "resources", "plot-schema.json")
102+
path = os.path.join(PROJECT_ROOT, "codegen", "resources", "plot-schema.json")
104103
shutil.copyfile(uri, path)
105104

106105

@@ -109,13 +108,13 @@ def overwrite_schema(url):
109108

110109
req = requests.get(url)
111110
assert req.status_code == 200
112-
path = os.path.join(project_root, "codegen", "resources", "plot-schema.json")
111+
path = os.path.join(PROJECT_ROOT, "codegen", "resources", "plot-schema.json")
113112
with open(path, "wb") as f:
114113
f.write(req.content)
115114

116115

117116
def overwrite_bundle_local(uri):
118-
path = os.path.join(project_root, "plotly", "package_data", "plotly.min.js")
117+
path = os.path.join(PROJECT_ROOT, "plotly", "package_data", "plotly.min.js")
119118
shutil.copyfile(uri, path)
120119

121120

@@ -125,13 +124,13 @@ def overwrite_bundle(url):
125124
req = requests.get(url)
126125
print("url:", url)
127126
assert req.status_code == 200
128-
path = os.path.join(project_root, "plotly", "package_data", "plotly.min.js")
127+
path = os.path.join(PROJECT_ROOT, "plotly", "package_data", "plotly.min.js")
129128
with open(path, "wb") as f:
130129
f.write(req.content)
131130

132131

133132
def overwrite_plotlyjs_version_file(plotlyjs_version):
134-
path = os.path.join(project_root, "plotly", "offline", "_plotlyjs_version.py")
133+
path = os.path.join(PROJECT_ROOT, "plotly", "offline", "_plotlyjs_version.py")
135134
with open(path, "w") as f:
136135
f.write(
137136
"""\
@@ -274,7 +273,7 @@ def update_schema_bundle_from_master():
274273
overwrite_schema_local(schema_uri)
275274

276275
# Update plotly.js url in package.json
277-
package_json_path = os.path.join(node_root, "package.json")
276+
package_json_path = os.path.join(NODE_ROOT, "package.json")
278277
with open(package_json_path, "r") as f:
279278
package_json = json.load(f)
280279

@@ -299,9 +298,18 @@ def update_plotlyjs_dev():
299298
run_codegen()
300299

301300

302-
if __name__ == "__main__":
303-
if "updateplotlyjsdev" in sys.argv:
301+
def main():
302+
if len(sys.argv) != 2:
303+
print(USAGE, file=sys.stderr)
304+
sys.exit(1)
305+
elif sys.argv[1] == "codegen":
306+
run_codegen()
307+
elif sys.argv[1] == "updateplotlyjsdev":
304308
update_plotlyjs_dev()
305-
elif "updateplotlyjs" in sys.argv:
309+
elif sys.argv[1] == "updateplotlyjs":
306310
print(plotly_js_version())
307311
update_plotlyjs(plotly_js_version())
312+
313+
314+
if __name__ == "__main__":
315+
main()

plotly/graph_objects/__init__.py

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

9139

10140
__all__.append("FigureWidget")
11141
orig_getattr = __getattr__
142+
143+
12144
def __getattr__(import_name):
13145
if import_name == "FigureWidget":
14146
try:
@@ -17,12 +149,13 @@ def __getattr__(import_name):
17149

18150
if Version(ipywidgets.__version__) >= Version("7.0.0"):
19151
from ..graph_objs._figurewidget import FigureWidget
152+
20153
return FigureWidget
21154
else:
22155
raise ImportError()
23156
except Exception:
24157
from ..missing_anywidget import FigureWidget
158+
25159
return FigureWidget
26160

27161
return orig_getattr(import_name)
28-

0 commit comments

Comments
 (0)