1
1
import os
2
2
import sys
3
+ import time
3
4
import platform
4
5
import json
6
+ import shutil
5
7
6
8
from setuptools import setup , Command
7
9
from setuptools .command .egg_info import egg_info
@@ -137,10 +139,10 @@ class NPM(Command):
137
139
]
138
140
139
141
def initialize_options (self ):
140
- pass
142
+ self . local = None
141
143
142
144
def finalize_options (self ):
143
- pass
145
+ self . set_undefined_options ( "updateplotlyjsdev" , ( "local" , "local" ))
144
146
145
147
def get_npm_name (self ):
146
148
npmName = "npm"
@@ -187,6 +189,14 @@ def run(self):
187
189
stdout = sys .stdout ,
188
190
stderr = sys .stderr ,
189
191
)
192
+ if self .local is not None :
193
+ plotly_archive = os .path .join (self .local , "plotly.js.tgz" )
194
+ check_call (
195
+ [npmName , "install" , plotly_archive ],
196
+ cwd = node_root ,
197
+ stdout = sys .stdout ,
198
+ stderr = sys .stderr ,
199
+ )
190
200
check_call (
191
201
[npmName , "run" , "build:prod" ],
192
202
cwd = node_root ,
@@ -224,6 +234,9 @@ def run(self):
224
234
225
235
perform_codegen ()
226
236
237
+ def overwrite_schema_local (uri ):
238
+ path = os .path .join (here , "codegen" , "resources" , "plot-schema.json" )
239
+ shutil .copyfile (uri , path )
227
240
228
241
def overwrite_schema (url ):
229
242
import requests
@@ -234,6 +247,9 @@ def overwrite_schema(url):
234
247
with open (path , "wb" ) as f :
235
248
f .write (req .content )
236
249
250
+ def overwrite_bundle_local (uri ):
251
+ path = os .path .join (here , "plotly" , "package_data" , "plotly.min.js" )
252
+ shutil .copyfile (uri , path )
237
253
238
254
def overwrite_bundle (url ):
239
255
import requests
@@ -281,7 +297,6 @@ def request_json(url):
281
297
req = requests .get (url )
282
298
return json .loads (req .content .decode ("utf-8" ))
283
299
284
-
285
300
def get_latest_publish_build_info (repo , branch ):
286
301
287
302
url = (
@@ -303,6 +318,11 @@ def get_latest_publish_build_info(repo, branch):
303
318
# Extract build info
304
319
return {p : build [p ] for p in ["vcs_revision" , "build_num" , "committer_date" ]}
305
320
321
+ def get_bundle_schema_local (local ):
322
+ plotly_archive = os .path .join (local , "plotly.js.tgz" )
323
+ plotly_bundle = os .path .join (local , "dist/plotly.min.js" )
324
+ plotly_schemas = os .path .join (local , "dist/plot-schema.json" )
325
+ return plotly_archive , plotly_bundle , plotly_schemas
306
326
307
327
def get_bundle_schema_urls (build_num ):
308
328
url = (
@@ -390,31 +410,45 @@ class UpdateBundleSchemaDevCommand(Command):
390
410
def initialize_options (self ):
391
411
self .devrepo = None
392
412
self .devbranch = None
413
+ self .local = None
393
414
394
415
def finalize_options (self ):
395
416
self .set_undefined_options ("updateplotlyjsdev" , ("devrepo" , "devrepo" ))
396
417
self .set_undefined_options ("updateplotlyjsdev" , ("devbranch" , "devbranch" ))
418
+ self .set_undefined_options ("updateplotlyjsdev" , ("local" , "local" ))
397
419
398
420
def run (self ):
399
- build_info = get_latest_publish_build_info (self .devrepo , self .devbranch )
421
+ if self .local is None :
422
+ build_info = get_latest_publish_build_info (self .devrepo , self .devbranch )
400
423
401
- archive_url , bundle_url , schema_url = get_bundle_schema_urls (
402
- build_info ["build_num" ]
403
- )
424
+ archive_url , bundle_url , schema_url = get_bundle_schema_urls (
425
+ build_info ["build_num" ]
426
+ )
427
+
428
+ # Update bundle in package data
429
+ overwrite_bundle (bundle_url )
404
430
405
- # Update bundle in package data
406
- overwrite_bundle (bundle_url )
431
+ # Update schema in package data
432
+ overwrite_schema (schema_url )
433
+ else :
434
+ # this info could be more informative but
435
+ # it doesn't seem as useful in a local context
436
+ # and requires dependencies and programming.
437
+ build_info = {"vcs_revision" : "local" , "committer_date" : str (time .time ())}
438
+ self .devrepo = self .local
439
+ self .devbranch = ""
407
440
408
- # Update schema in package data
409
- overwrite_schema (schema_url )
441
+ archive_uri , bundle_uri , schema_uri = get_bundle_schema_local (self .local )
442
+ overwrite_bundle_local (bundle_uri )
443
+ overwrite_schema_local (schema_uri )
410
444
411
445
# Update plotly.js url in package.json
412
446
package_json_path = os .path .join (node_root , "package.json" )
413
447
with open (package_json_path , "r" ) as f :
414
448
package_json = json .load (f )
415
449
416
450
# Replace version with bundle url
417
- package_json ["dependencies" ]["plotly.js" ] = archive_url
451
+ package_json ["dependencies" ]["plotly.js" ] = archive_url if self . local is None else archive_uri
418
452
with open (package_json_path , "w" ) as f :
419
453
json .dump (package_json , f , indent = 2 )
420
454
@@ -430,11 +464,13 @@ class UpdatePlotlyJsDevCommand(Command):
430
464
user_options = [
431
465
("devrepo=" , None , "Repository name" ),
432
466
("devbranch=" , None , "branch or pull/number" ),
467
+ ("local=" , None , "local copy of repo, used by itself" )
433
468
]
434
469
435
470
def initialize_options (self ):
436
471
self .devrepo = "plotly/plotly.js"
437
472
self .devbranch = "master"
473
+ self .local = None
438
474
439
475
def finalize_options (self ):
440
476
pass
0 commit comments