11"""Utility command runner."""
22
33import argparse
4- from distutils import log
4+ import logging
55import json
66import os
77import platform
1111import sys
1212import time
1313
14- from codegen import perform_codegen
14+ from codegen import perform_codegen , reformat_code
1515
1616
17+ LOGGER = logging .getLogger (__name__ )
1718PROJECT_ROOT = os .path .dirname (os .path .abspath (__file__ ))
1819NODE_ROOT = os .path .join (PROJECT_ROOT , "js" )
1920NODE_MODULES = os .path .join (NODE_ROOT , "node_modules" )
@@ -54,19 +55,19 @@ def install_js_deps(local):
5455
5556 skip_npm = os .environ .get ("SKIP_NPM" , False )
5657 if skip_npm :
57- log .info ("Skipping npm-installation" )
58+ LOGGER .info ("Skipping npm-installation" )
5859 return
5960
6061 if not has_npm :
61- log .error (
62+ LOGGER .error (
6263 "`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo"
6364 )
6465
6566 env = os .environ .copy ()
6667 env ["PATH" ] = NPM_PATH
6768
6869 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..." )
7071 check_call (
7172 [npmName , "install" ],
7273 cwd = NODE_ROOT ,
@@ -130,9 +131,7 @@ def overwrite_plotlyjs_version_file(plotlyjs_version):
130131 # DO NOT EDIT
131132# This file is generated by the updatebundle commands.py command
132133__plotlyjs_version__ = "{plotlyjs_version}"
133- """ .format (
134- plotlyjs_version = plotlyjs_version
135- )
134+ """ .format (plotlyjs_version = plotlyjs_version )
136135 )
137136
138137
@@ -223,7 +222,6 @@ def update_plotlyjs(plotly_js_version):
223222
224223# Update the plotly.js schema and bundle from master
225224def update_schema_bundle_from_master ():
226-
227225 if "--devrepo" in sys .argv :
228226 devrepo = sys .argv [sys .argv .index ("--devrepo" ) + 1 ]
229227 else :
@@ -295,9 +293,15 @@ def parse_args():
295293 subparsers = parser .add_subparsers (dest = "cmd" , help = "Available subcommands" )
296294
297295 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+ )
299299
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+ )
301305
302306 p_updateplotlyjs = subparsers .add_parser ("updateplotlyjs" , help = "update plotly.js" )
303307
@@ -312,6 +316,9 @@ def main():
312316 if args .cmd == "codegen" :
313317 perform_codegen (noformat = args .noformat )
314318
319+ elif args .cmd == "format" :
320+ reformat_code ()
321+
315322 elif args .cmd == "updateplotlyjsdev" :
316323 update_plotlyjs_dev ()
317324
0 commit comments