From 5d2b7cab08e9bce1b25fa24f78d4ec81c731ac8e Mon Sep 17 00:00:00 2001 From: Tom Krizek Date: Tue, 7 Jun 2022 16:06:05 +0200 Subject: [PATCH] Enforce Python codestyle with black Black is an opinionated tool for auto-formatting Python code so we no longer have to worry about the codestyle. For the codestyle decisions and discussion, refer to the upstream documentation [1]. [1] https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html --- .gitlab-ci.yml | 13 +++++++++++++ doc/dev/style.md | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 466c3d1d41..a8c54d47e1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -427,6 +427,19 @@ misc: expire_in: "1 day" when: on_failure +black: + <<: *precheck_job + needs: [] + script: + - black $(git ls-files '*.py') + - git diff > black.patch + - if test "$(git status --porcelain | grep -Ev '\?\?' | wc -l)" -gt "0"; then git status --short; exit 1; fi + artifacts: + paths: + - black.patch + expire_in: "1 week" + when: on_failure + clang-format: <<: *precheck_job needs: [] diff --git a/doc/dev/style.md b/doc/dev/style.md index 3cc0a0aec5..f4b79c5af5 100644 --- a/doc/dev/style.md +++ b/doc/dev/style.md @@ -855,9 +855,9 @@ name server. However, BIND 9 may use it for its system test environment, and in some cases for generating source or documentation files which are then committed to to the git repository. -For Python coding, we abide by the Python style guidelines described -in [PEP8](http://www.python.org/dev/peps/pep-0008/), with a few -modifications: +For Python coding, we enforce a common codestyle using the tool +[black](https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html) +There are also a few other requirements: * The `__init__()` method should always be the first one declared in a class definition, like so: