]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Enforce Python codestyle with black
authorTom Krizek <tkrizek@isc.org>
Tue, 7 Jun 2022 14:06:05 +0000 (16:06 +0200)
committerTom Krizek <tkrizek@isc.org>
Wed, 8 Jun 2022 11:29:01 +0000 (13:29 +0200)
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
doc/dev/style.md

index 3f6e8dcb35acde41efc892e492b2e42f6ec4f2c5..ecb851c8df5973660b97370f852264df8cf75d4d 100644 (file)
@@ -428,6 +428,19 @@ misc:
     expire_in: "1 day"
     when: on_failure
 
+black:
+  <<: *precheck_job
+  needs: []
+  script:
+    - black $(git ls-files '*.py' '*.py.in')
+    - 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: []
index 6781835fd7771ab3d92101295b36205ffae00ec9..09e208bd9dd4c7bcc6e0d845e809bd44c6b18a3b 100644 (file)
@@ -852,7 +852,9 @@ program's inputs or operation.
 
 BIND 9 contains some optional tools written in Python, in the `bin/python` subdirectory.  Python scripts are stored in the git repository as `{toolname}.py.in`; and `{toolname}.py` will be generated by `configure` (which determines, among other things, the path to the Python interpreter).
 
-For Python coding, we abide by the Python style guidelines described [here](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: