From c9523d93422ae1dd8dfa9889d7e4b83538c2fc8e Mon Sep 17 00:00:00 2001 From: "Jason M. Gates" Date: Thu, 24 Mar 2022 07:51:47 -0600 Subject: [PATCH] Add YAPF job --- .gitlab-ci.yml | 23 ++++++++++++++++++++++- .style.yapf | 18 ++++++++++++++++++ tests/requirements.txt | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 .style.yapf diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8b5b091..1585d92 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -146,7 +146,7 @@ pytest: junit: tests/coverage.xml -# Ensure we adhere to PEP8. +# Ensure we pass the `flake8` linter. flake8: stage: test timeout: 5m @@ -157,6 +157,27 @@ flake8: --exclude=shelllogger-env +# Ensure we adhere to our style guide.variables: +yapf: + stage: test + timeout: 5m + cache: + <<: *global_cache + script: + - python3 -m yapf + --diff + --recursive + . > yapf.diff.txt + - |- + if [[ "$(wc -l yapf.diff.txt | awk '{print $1}')" != "0" ]]; then + echo "----------" + echo "Your code does not match our Python style guide." + echo "Run 'yapf -i' on the following files:" + grep "^+++.*(reformatted)$" yapf.diff.txt | awk '{print $2}' + exit 1 + fi + + # Ensure the examples run without problems. examples: stage: test diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..4e39ab2 --- /dev/null +++ b/.style.yapf @@ -0,0 +1,18 @@ +# YAPF Style Configuration + +# See: /~https://github.com/google/yapf#knobs for available options + +[style] +# Base style +based_on_style = pep8 + +# Customizations +arithmetic_precedence_indication = True +blank_line_before_nested_class_or_def = True +coalesce_brackets = True +dedent_closing_brackets = True +join_multiple_lines = False +split_all_comma_separated_values = True +split_before_arithmetic_operator = True +split_before_dot = True +split_complex_comprehension = True diff --git a/tests/requirements.txt b/tests/requirements.txt index e151467..773a547 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -6,3 +6,4 @@ psutil pytest >= 6.2 pytest-cov >= 2.12 pytest-mock >= 3.6 +yapf