summaryrefslogtreecommitdiff
path: root/system/tools/scripts/yapf_checker.py
diff options
context:
space:
mode:
authorZach Johnson <zachoverflow@google.com>2020-05-18 12:52:26 -0700
committerZach Johnson <zachoverflow@google.com>2020-05-18 12:52:51 -0700
commit764d3b76a687a54dfdf50dfb6925a4ff2e362555 (patch)
tree28894413f273c4a17a0bc8e4de17311489f63845 /system/tools/scripts/yapf_checker.py
parent5ff3191fa8aba657bbdb1ab2cf46b36e52a518d7 (diff)
Format python files with extended line length now allowed
Bug: 156858180 Test: cert/run --host Tag: #gd-refactor Change-Id: I45ab86f366316246f14b24dd83f66684badf22e0
Diffstat (limited to 'system/tools/scripts/yapf_checker.py')
-rwxr-xr-xsystem/tools/scripts/yapf_checker.py35
1 files changed, 10 insertions, 25 deletions
diff --git a/system/tools/scripts/yapf_checker.py b/system/tools/scripts/yapf_checker.py
index f6dd2c9d25..62a753e7d7 100755
--- a/system/tools/scripts/yapf_checker.py
+++ b/system/tools/scripts/yapf_checker.py
@@ -23,9 +23,7 @@ PYTHONPATH_KEY = 'PYTHONPATH'
COMMIT_ID_ENV_KEY = 'PREUPLOAD_COMMIT'
ANDROID_BUILD_TOP_KEY = 'ANDROID_BUILD_TOP'
DEFAULT_YAPF_DIR = 'external/yapf'
-GIT_COMMAND = [
- 'git', 'diff-tree', '--no-commit-id', '--name-only', '--diff-filter=d'
-]
+GIT_COMMAND = ['git', 'diff-tree', '--no-commit-id', '--name-only', '--diff-filter=d']
def main():
@@ -47,8 +45,7 @@ def main():
# Gather changed Python files
commit_id = os.environ[COMMIT_ID_ENV_KEY]
full_git_command = GIT_COMMAND + ['-r', commit_id]
- files = subprocess.check_output(full_git_command).decode(
- 'utf-8').splitlines()
+ files = subprocess.check_output(full_git_command).decode('utf-8').splitlines()
full_files = [os.path.abspath(f) for f in files if f.endswith('.py')]
if not full_files:
return
@@ -58,32 +55,20 @@ def main():
yapf_binary = os.path.join(yapf_dir, 'yapf')
# Run YAPF
- full_yapf_command = [
- "%s=$%s:%s" % (PYTHONPATH_KEY, PYTHONPATH_KEY, yapf_dir), 'python3',
- yapf_binary, '-d', '-p'
- ] + full_files
+ full_yapf_command = ["%s=$%s:%s" % (PYTHONPATH_KEY, PYTHONPATH_KEY, yapf_dir), 'python3', yapf_binary, '-d', '-p'
+ ] + full_files
environment = os.environ.copy()
environment[PYTHONPATH_KEY] = environment[PYTHONPATH_KEY] + ":" + yapf_dir
- result = subprocess.run(
- full_yapf_command[1:],
- env=environment,
- stderr=subprocess.STDOUT,
- stdout=subprocess.PIPE)
+ result = subprocess.run(full_yapf_command[1:], env=environment, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
if result.returncode != 0 or result.stdout:
logging.error(result.stdout.decode('utf-8').strip())
logging.error('INVALID FORMATTING, return code %d', result.returncode)
- logging.error('To re-run the format command:\n\n'
- ' %s\n' % ' '.join(full_yapf_command))
- yapf_inplace_format = ' '.join([
- "%s=$%s:%s" % (PYTHONPATH_KEY, PYTHONPATH_KEY,
- yapf_dir), 'python3', yapf_binary, '-p', '-i'
- ] + full_files)
- logging.error('If this is a legitimate format error, please run:\n\n'
- ' %s\n' % yapf_inplace_format)
- logging.error(
- 'CAVEAT: Currently, this format the entire Python file if you modify even part of it'
- )
+ logging.error('To re-run the format command:\n\n' ' %s\n' % ' '.join(full_yapf_command))
+ yapf_inplace_format = ' '.join(
+ ["%s=$%s:%s" % (PYTHONPATH_KEY, PYTHONPATH_KEY, yapf_dir), 'python3', yapf_binary, '-p', '-i'] + full_files)
+ logging.error('If this is a legitimate format error, please run:\n\n' ' %s\n' % yapf_inplace_format)
+ logging.error('CAVEAT: Currently, this format the entire Python file if you modify even part of it')
exit(1)