From d93999258998264bf88f526067bbfd6021d0e709 Mon Sep 17 00:00:00 2001 From: Peter Wen Date: Wed, 17 Jun 2020 17:33:49 +0000 Subject: [PATCH] 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 Reviewed-by: Edward Lesmes Auto-Submit: Peter Wen --- git_cl.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/git_cl.py b/git_cl.py index fe92b2cc31..98ab9d78c1 100755 --- a/git_cl.py +++ b/git_cl.py @@ -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: