1
1
"""Utility command runner."""
2
2
3
3
import argparse
4
- from distutils import log
4
+ import logging
5
5
import json
6
6
import os
7
7
import platform
11
11
import sys
12
12
import time
13
13
14
- from codegen import perform_codegen
14
+ from codegen import perform_codegen , reformat_code
15
15
16
16
17
+ LOGGER = logging .getLogger (__name__ )
17
18
PROJECT_ROOT = os .path .dirname (os .path .abspath (__file__ ))
18
19
NODE_ROOT = os .path .join (PROJECT_ROOT , "js" )
19
20
NODE_MODULES = os .path .join (NODE_ROOT , "node_modules" )
@@ -54,19 +55,19 @@ def install_js_deps(local):
54
55
55
56
skip_npm = os .environ .get ("SKIP_NPM" , False )
56
57
if skip_npm :
57
- log .info ("Skipping npm-installation" )
58
+ LOGGER .info ("Skipping npm-installation" )
58
59
return
59
60
60
61
if not has_npm :
61
- log .error (
62
+ LOGGER .error (
62
63
"`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo"
63
64
)
64
65
65
66
env = os .environ .copy ()
66
67
env ["PATH" ] = NPM_PATH
67
68
68
69
if has_npm :
69
- log .info ("Installing build dependencies with npm. This may take a while..." )
70
+ LOGGER .info ("Installing build dependencies with npm. This may take a while..." )
70
71
check_call (
71
72
[npmName , "install" ],
72
73
cwd = NODE_ROOT ,
@@ -130,9 +131,7 @@ def overwrite_plotlyjs_version_file(plotlyjs_version):
130
131
# DO NOT EDIT
131
132
# This file is generated by the updatebundle commands.py command
132
133
__plotlyjs_version__ = "{plotlyjs_version}"
133
- """ .format (
134
- plotlyjs_version = plotlyjs_version
135
- )
134
+ """ .format (plotlyjs_version = plotlyjs_version )
136
135
)
137
136
138
137
@@ -223,7 +222,6 @@ def update_plotlyjs(plotly_js_version):
223
222
224
223
# Update the plotly.js schema and bundle from master
225
224
def update_schema_bundle_from_master ():
226
-
227
225
if "--devrepo" in sys .argv :
228
226
devrepo = sys .argv [sys .argv .index ("--devrepo" ) + 1 ]
229
227
else :
@@ -295,9 +293,15 @@ def parse_args():
295
293
subparsers = parser .add_subparsers (dest = "cmd" , help = "Available subcommands" )
296
294
297
295
p_codegen = subparsers .add_parser ("codegen" , help = "generate code" )
298
- p_codegen .add_argument ("--noformat" , action = "store_true" , help = "prevent reformatting" )
296
+ p_codegen .add_argument (
297
+ "--noformat" , action = "store_true" , help = "prevent reformatting"
298
+ )
299
299
300
- p_updateplotlyjsdev = subparsers .add_parser ("updateplotlyjsdev" , help = "update plotly.js for development" )
300
+ p_format = subparsers .add_parser ("format" , help = "reformat code" )
301
+
302
+ p_updateplotlyjsdev = subparsers .add_parser (
303
+ "updateplotlyjsdev" , help = "update plotly.js for development"
304
+ )
301
305
302
306
p_updateplotlyjs = subparsers .add_parser ("updateplotlyjs" , help = "update plotly.js" )
303
307
@@ -312,6 +316,9 @@ def main():
312
316
if args .cmd == "codegen" :
313
317
perform_codegen (noformat = args .noformat )
314
318
319
+ elif args .cmd == "format" :
320
+ reformat_code ()
321
+
315
322
elif args .cmd == "updateplotlyjsdev" :
316
323
update_plotlyjs_dev ()
317
324
0 commit comments