From fa40bfa39bf0399570558e24bd3f8680a8130ac2 Mon Sep 17 00:00:00 2001 From: Andrew Grieve Date: Tue, 7 Jan 2020 02:32:57 +0000 Subject: [PATCH] Update "git cl format --python" to default to PEP-8 This matches the recent change Chromium's Python style guide. This also changes the .style.yapf in depot_tools to be explicit about the style used in this repo. Bug: 846432 Change-Id: I4947a90aec1739a9a86ffc9bfc5eacc1182dc186 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1987006 Reviewed-by: Robbie Iannucci Commit-Queue: Andrew Grieve --- .style.yapf | 4 +++- git_cl.py | 13 +++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.style.yapf b/.style.yapf index de0c6a70f..24681e21f 100644 --- a/.style.yapf +++ b/.style.yapf @@ -1,2 +1,4 @@ [style] -based_on_style = chromium +based_on_style = pep8 +indent_width = 2 +column_limit = 80 diff --git a/git_cl.py b/git_cl.py index fe0c00f2c..cf30eff8c 100755 --- a/git_cl.py +++ b/git_cl.py @@ -5262,10 +5262,6 @@ def CMDformat(parser, args): if sys.platform.startswith('win'): yapf_tool += '.bat' - # If we couldn't find a yapf file we'll default to the chromium style - # specified in depot_tools. - chromium_default_yapf_style = os.path.join(depot_tools_path, - YAPF_CONFIG_FILENAME) # Used for caching. yapf_configs = {} for f in python_diff_files: @@ -5295,11 +5291,12 @@ def CMDformat(parser, args): yapfignore_patterns) for f in filtered_py_files: - yapf_config = _FindYapfConfigFile(f, yapf_configs, top_dir) - if yapf_config is None: - yapf_config = chromium_default_yapf_style + yapf_style = _FindYapfConfigFile(f, yapf_configs, top_dir) + # Default to pep8 if not .style.yapf is found. + if not yapf_style: + yapf_style = 'pep8' - cmd = [yapf_tool, '--style', yapf_config, f] + cmd = [yapf_tool, '--style', yapf_style, f] has_formattable_lines = False if not opts.full: