diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 000000000..c29ca6bdb --- /dev/null +++ b/.style.yapf @@ -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 diff --git a/Makefile b/Makefile index 8bbaa42f0..41b48faa6 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,13 @@ SHA := $(shell git rev-parse --short HEAD ) REPO := quay.io/quay/quay 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 all: clean pkgs test build @@ -92,3 +99,22 @@ clean: rm -rf build rm -rf conf/stack 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 diff --git a/ci/pipelines/pull-requests.yaml b/ci/pipelines/pull-requests.yaml index 9d27e97d0..946933046 100644 --- a/ci/pipelines/pull-requests.yaml +++ b/ci/pipelines/pull-requests.yaml @@ -25,6 +25,37 @@ resources: disable_forks: false 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 max_in_flight: 4 plan: diff --git a/ci/tasks/style.yaml b/ci/tasks/style.yaml new file mode 100644 index 000000000..56ea87b4d --- /dev/null +++ b/ci/tasks/style.yaml @@ -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 diff --git a/requirements-dev.txt b/requirements-dev.txt index 916966dbc..0cdbc4aea 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,3 +2,4 @@ ipython pylint ipdb tqdm +yapf==0.15.2 diff --git a/requirements-nover.txt b/requirements-nover.txt index d8a243c75..6bad4c9b9 100644 --- a/requirements-nover.txt +++ b/requirements-nover.txt @@ -72,3 +72,4 @@ xhtml2pdf recaptcha2 mockredispy cnr +yapf