Commit d9399925 authored by Peter Wen's avatar Peter Wen Committed by LUCI CQ

Support formatting python3 scripts (reland)

Original CL: https://crrev.com/c/2241792

Fix Windows use case by calling yapf directly without going through
yapf.bat.

Bug: 1062053,1095581
Change-Id: I31a9f09cba655d6ac1b4da9874a24a41aa007b17
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2249606
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
parent 821aa2a0
......@@ -4894,8 +4894,6 @@ def CMDformat(parser, args):
if python_diff_files and not py_explicitly_disabled:
depot_tools_path = os.path.dirname(os.path.abspath(__file__))
yapf_tool = os.path.join(depot_tools_path, 'yapf')
if sys.platform.startswith('win'):
yapf_tool += '.bat'
# Used for caching.
yapf_configs = {}
......@@ -4931,7 +4929,13 @@ def CMDformat(parser, args):
if not yapf_style:
yapf_style = 'pep8'
cmd = [yapf_tool, '--style', yapf_style, f]
with open(f, 'r') as py_f:
if 'python3' in py_f.readline():
vpython_script = 'vpython3'
else:
vpython_script = 'vpython'
cmd = [vpython_script, yapf_tool, '--style', yapf_style, f]
has_formattable_lines = False
if not opts.full:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment