From 2ba05f1672dc958412ab29fa994c722bfca1cff0 Mon Sep 17 00:00:00 2001 From: Peter Wen Date: Mon, 15 Jun 2020 16:22:10 +0000 Subject: [PATCH] Support formatting python3 scripts Use vpython or vpython3 to invoke yapf depending on the shebang line for each file. Bug: 1062053 Change-Id: I497fa48c08aa6052a2b06df7cc7f18e2154ab898 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2241792 Commit-Queue: Edward Lesmes Reviewed-by: Edward Lesmes Auto-Submit: Peter Wen --- git_cl.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/git_cl.py b/git_cl.py index fe92b2cc3..49a9f12aa 100755 --- a/git_cl.py +++ b/git_cl.py @@ -4931,7 +4931,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: