88import os
99import sys
1010import platform
11-
12- plotly_js_version = '1.38.2'
11+ import json
1312
1413exec (open ('plotly/version.py' ).read ())
1514
2221 os .environ .get ('PATH' , os .defpath ),
2322])
2423
24+
25+ # Load plotly.js version from js/package.json
26+ def plotly_js_version ():
27+ with open ('js/package.json' , 'rt' ) as f :
28+ package_json = json .load (f )
29+ version = package_json ['dependencies' ]['plotly.js' ]
30+
31+ return version
32+
33+
2534def readme ():
2635 with open ('README.rst' ) as f :
2736 return f .read ()
@@ -138,13 +147,14 @@ def finalize_options(self):
138147
139148 def run (self ):
140149 if sys .version_info .major != 3 or sys .version_info .minor < 6 :
141- raise ImportError ('Code generation must be executed with Python >= 3.6' )
150+ raise ImportError (
151+ 'Code generation must be executed with Python >= 3.6' )
142152
143153 from codegen import perform_codegen
144154 perform_codegen ()
145155
146156
147- class DownloadSchemaCommand (Command ):
157+ class UpdateSchemaCommand (Command ):
148158 description = 'Download latest version of the plot-schema JSON file'
149159 user_options = []
150160
@@ -160,14 +170,14 @@ def run(self):
160170
161171 import urllib .request
162172 url = ('https://raw.githubusercontent.com/plotly/plotly.js/'
163- 'v%s/dist/plot-schema.json' % plotly_js_version )
173+ 'v%s/dist/plot-schema.json' % plotly_js_version () )
164174 with urllib .request .urlopen (url ) as response :
165175
166176 with open ('plotly/package_data/plot-schema.json' , 'wb' ) as f :
167177 f .write (response .read ())
168178
169179
170- class DownloadPlotlyJsCommand (Command ):
180+ class UpdateBundleCommand (Command ):
171181 description = 'Download latest version of the plot-schema JSON file'
172182 user_options = []
173183
@@ -183,13 +193,29 @@ def run(self):
183193
184194 import urllib .request
185195 url = ('https://raw.githubusercontent.com/plotly/plotly.js/'
186- 'v%s/dist/plotly.min.js' % plotly_js_version )
196+ 'v%s/dist/plotly.min.js' % plotly_js_version () )
187197 with urllib .request .urlopen (url ) as response :
188198
189199 with open ('plotly/package_data/plotly.min.js' , 'wb' ) as f :
190200 f .write (response .read ())
191201
192202
203+ class UpdatePlotlyJsCommand (Command ):
204+ description = 'Update project to a new version of plotly.js'
205+ user_options = []
206+
207+ def initialize_options (self ):
208+ pass
209+
210+ def finalize_options (self ):
211+ pass
212+
213+ def run (self ):
214+ self .run_command ('updatebundle' )
215+ self .run_command ('updateschema' )
216+ self .run_command ('codegen' )
217+
218+
193219graph_objs_packages = [
194220 d [0 ] for d in os .walk ('plotly/graph_objs' )
195221 if not d [0 ].endswith ('__pycache__' )]
@@ -260,7 +286,8 @@ def run(self):
260286 'sdist' : js_prerelease (sdist , strict = True ),
261287 'jsdeps' : NPM ,
262288 'codegen' : CodegenCommand ,
263- 'updateschema' : DownloadSchemaCommand ,
264- 'updateplotlyjs' : DownloadPlotlyJsCommand
289+ 'updateschema' : UpdateSchemaCommand ,
290+ 'updatebundle' : UpdateBundleCommand ,
291+ 'updateplotlyjs' : js_prerelease (UpdatePlotlyJsCommand )
265292 },
266293)
0 commit comments