Update tooling to use yapf for Python file formatting (issue #2171)

This commit is contained in:
Marshall Greenblatt
2017-05-28 15:03:42 +02:00
parent d4f06e3806
commit 59606b88d2
28 changed files with 6483 additions and 6 deletions

26
tools/yapf_util.py Normal file
View File

@ -0,0 +1,26 @@
# Copyright (c) 2017 The Chromium Embedded Framework Authors. All rights
# reserved. Use of this source code is governed by a BSD-style license that
# can be found in the LICENSE file
from exec_util import exec_cmd
import os
import sys
# Script directory.
script_dir = os.path.dirname(__file__)
root_dir = os.path.join(script_dir, os.pardir)
def yapf_format(file_name, file_contents):
# Reads .style.yapf in the root_dir when specifying contents via stdin.
result = exec_cmd("%s %s/yapf" % (sys.executable, script_dir), root_dir,
file_contents)
if result['err'] != '':
print "yapf error: %s" % result['err']
if result['out'] != '':
output = result['out']
if sys.platform == 'win32':
# Convert to Unix line endings.
output = output.replace("\r", "")
return output
return None