Merge pull request #2335 from coreos-inc/FEAT-yapf-autoformat-py
feat(yapf): add autoformatting with yapf
This commit is contained in:
commit
11c3d1d5c8
6 changed files with 111 additions and 0 deletions
37
.style.yapf
Normal file
37
.style.yapf
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
[style]
|
||||||
|
based_on_style = chromium
|
||||||
|
COLUMN_LIMIT=99
|
||||||
|
INDENT_WIDTH=2
|
||||||
|
BLANK_LINE_BEFORE_CLASS_DOCSTRING=False
|
||||||
|
#True
|
||||||
|
ALIGN_CLOSING_BRACKET_WITH_VISUAL_INDENT=True
|
||||||
|
# False
|
||||||
|
ALLOW_MULTILINE_DICTIONARY_KEYS=True
|
||||||
|
# False
|
||||||
|
BLANK_LINE_BEFORE_NESTED_CLASS_OR_DEF=False
|
||||||
|
# False
|
||||||
|
COALESCE_BRACKETS=True
|
||||||
|
DEDENT_CLOSING_BRACKETS=False
|
||||||
|
CONTINUATION_INDENT_WIDTH=2
|
||||||
|
# False
|
||||||
|
INDENT_DICTIONARY_VALUE=True
|
||||||
|
JOIN_MULTIPLE_LINES=False
|
||||||
|
# True
|
||||||
|
SPACE_BETWEEN_ENDING_COMMA_AND_CLOSING_BRACKET=False
|
||||||
|
# True
|
||||||
|
SPLIT_BEFORE_NAMED_ASSIGNS=False
|
||||||
|
SPLIT_PENALTY_AFTER_OPENING_BRACKET=30
|
||||||
|
SPLIT_PENALTY_AFTER_UNARY_OPERATOR=10000
|
||||||
|
SPLIT_PENALTY_BEFORE_IF_EXPR=0
|
||||||
|
SPLIT_PENALTY_BITWISE_OPERATOR=300
|
||||||
|
SPLIT_PENALTY_EXCESS_CHARACTER=10000
|
||||||
|
SPLIT_PENALTY_FOR_ADDED_LINE_SPLIT=30
|
||||||
|
SPLIT_PENALTY_IMPORT_NAMES=450
|
||||||
|
SPLIT_PENALTY_LOGICAL_OPERATOR=300
|
||||||
|
USE_TABS=False
|
||||||
|
SPLIT_ARGUMENTS_WHEN_COMMA_TERMINATED=False
|
||||||
|
# Align closing bracket with visual indentation.
|
||||||
|
align_closing_bracket_with_visual_indent=True
|
||||||
|
|
||||||
|
# Allow lambdas to be formatted on more than one line.
|
||||||
|
allow_multiline_lambdas=True
|
26
Makefile
26
Makefile
|
@ -4,6 +4,13 @@ SHA := $(shell git rev-parse --short HEAD )
|
||||||
REPO := quay.io/quay/quay
|
REPO := quay.io/quay/quay
|
||||||
TAG := $(REPO):$(SHA)
|
TAG := $(REPO):$(SHA)
|
||||||
|
|
||||||
|
MODIFIED_FILES_COUNT = $(shell git diff --name-only origin/master | grep -E .+\.py$ | wc -l)
|
||||||
|
GIT_MERGE_BASED = $(shell git merge-base origin/master HEAD)
|
||||||
|
MODIFIED_FILES = $(shell git diff --name-only $(GIT_MERGE_BASED) | grep -E .+\.py$ | paste -sd ' ')
|
||||||
|
|
||||||
|
show-modified:
|
||||||
|
echo $(MODIFIED_FILES)
|
||||||
|
|
||||||
.PHONY: all unit test pkgs build run clean
|
.PHONY: all unit test pkgs build run clean
|
||||||
|
|
||||||
all: clean pkgs test build
|
all: clean pkgs test build
|
||||||
|
@ -92,3 +99,22 @@ clean:
|
||||||
rm -rf build
|
rm -rf build
|
||||||
rm -rf conf/stack
|
rm -rf conf/stack
|
||||||
rm -rf screenshots
|
rm -rf screenshots
|
||||||
|
|
||||||
|
|
||||||
|
yapf-all:
|
||||||
|
yapf -r . -p -i
|
||||||
|
|
||||||
|
|
||||||
|
yapf-diff:
|
||||||
|
if [ $(MODIFIED_FILES_COUNT) -ne 0 ]; then yapf -d -p $(MODIFIED_FILES) ; fi
|
||||||
|
|
||||||
|
yapf:
|
||||||
|
ifneq (0,$(shell git diff-index HEAD | wc -l))
|
||||||
|
echo "Failed, git dirty" && false
|
||||||
|
else ifneq (0,$(shell yapf -d -p $(MODIFIED_FILES) | wc -l))
|
||||||
|
yapf -i -p $(MODIFIED_FILES)
|
||||||
|
git commit -a -m "code-stye Yapf: $(MODIFIED_FILES_COUNT) files updated" -m "$(MODIFIED_FILES)"
|
||||||
|
endif
|
||||||
|
|
||||||
|
yapf-test:
|
||||||
|
if [ `yapf -d -p $(MODIFIED_FILES) | wc -l` -gt 0 ] ; then false ; else true ;fi
|
||||||
|
|
|
@ -25,6 +25,37 @@ resources:
|
||||||
disable_forks: false
|
disable_forks: false
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
- name: style
|
||||||
|
max_in_flight: 4
|
||||||
|
plan:
|
||||||
|
- get: quay-pull-request
|
||||||
|
trigger: true
|
||||||
|
version: every
|
||||||
|
|
||||||
|
- get: build-image
|
||||||
|
|
||||||
|
- put: quay-pull-request
|
||||||
|
params:
|
||||||
|
path: quay-pull-request
|
||||||
|
context: style
|
||||||
|
status: pending
|
||||||
|
|
||||||
|
- task: style
|
||||||
|
image: build-image
|
||||||
|
file: quay-pull-request/ci/tasks/style.yaml
|
||||||
|
on_success:
|
||||||
|
put: quay-pull-request
|
||||||
|
params:
|
||||||
|
path: quay-pull-request
|
||||||
|
context: style
|
||||||
|
status: success
|
||||||
|
on_failure:
|
||||||
|
put: quay-pull-request
|
||||||
|
params:
|
||||||
|
path: quay-pull-request
|
||||||
|
context: style
|
||||||
|
status: failure
|
||||||
|
|
||||||
- name: karma
|
- name: karma
|
||||||
max_in_flight: 4
|
max_in_flight: 4
|
||||||
plan:
|
plan:
|
||||||
|
|
15
ci/tasks/style.yaml
Normal file
15
ci/tasks/style.yaml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
platform: linux
|
||||||
|
inputs:
|
||||||
|
- name: quay-pull-request
|
||||||
|
run:
|
||||||
|
path: /bin/bash
|
||||||
|
args:
|
||||||
|
- -c
|
||||||
|
- |
|
||||||
|
set -eux
|
||||||
|
pip install --quiet -r quay-pull-request/requirements-dev.txt
|
||||||
|
cd quay-pull-request
|
||||||
|
export GIT_MERGE_BASED=`git merge-base origin/master HEAD`
|
||||||
|
export MODIFIED_FILES=`git diff --name-only $(GIT_MERGE_BASED) | grep -E .+\.py$ | paste -sd ' '`
|
||||||
|
if [ `yapf -d -p $(MODIFIED_FILES) | wc -l` -gt 0 ] ; then false ; else true ;fi
|
|
@ -2,3 +2,4 @@ ipython
|
||||||
pylint
|
pylint
|
||||||
ipdb
|
ipdb
|
||||||
tqdm
|
tqdm
|
||||||
|
yapf==0.15.2
|
||||||
|
|
|
@ -72,3 +72,4 @@ xhtml2pdf
|
||||||
recaptcha2
|
recaptcha2
|
||||||
mockredispy
|
mockredispy
|
||||||
cnr
|
cnr
|
||||||
|
yapf
|
||||||
|
|
Reference in a new issue