From 3dc618a5716531e3b92a2bd854287038637c7534 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 30 Mar 2021 10:10:04 +0200 Subject: [PATCH] add black configuration (#52457) --- .git-blame-ignore-revs | 2 ++ .pre-commit-config.yaml | 8 ++++++++ Jenkinsfile | 2 +- README | 10 ++++++++++ tox.ini | 8 ++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .git-blame-ignore-revs create mode 100644 .pre-commit-config.yaml diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..348e62dfb --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# misc: apply black +4bb33d3d3c62516cfdb1ff5bba9216936a07d368 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..a14705c76 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + args: ['--target-version', 'py37', '--skip-string-normalization', '--line-length', '110'] diff --git a/Jenkinsfile b/Jenkinsfile index 56ed920ff..407e166e5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { sh """ python3 -m venv ${env.TMPDIR}/venv/ ${env.TMPDIR}/venv/bin/pip install tox -PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -rv -e rbac-py3-dj111,authentic-py3-dj111-drf39,authentic-py3-dj22-drf39,pylint""" +PGPORT=`python -c 'import struct; import socket; s=socket.socket(); s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", 1, 0)); s.bind(("", 0)); print(s.getsockname()[1]); s.close()'` pg_virtualenv -o fsync=off ${env.TMPDIR}/venv/bin/tox -rv -e code-style,rbac-py3-dj111,authentic-py3-dj111-drf39,authentic-py3-dj22-drf39,pylint""" } post { always { diff --git a/README b/README index 9c53a4727..1a8203b4a 100644 --- a/README +++ b/README @@ -68,6 +68,16 @@ Upgrade using a previous one you must first upgrade to 2.1.12 before tempting upgrade to a release later than 2.2.0. +Code Style +========== + +black is used to format the code, using thoses parameters: + + black --target-version py37 --skip-string-normalization --line-length 110 + +There is .pre-commit-config.yaml to use pre-commit to automatically run black +before commits. (execute `pre-commit install` to install the git hook.) + Support ======= diff --git a/tox.ini b/tox.ini index 56ab9f9cc..334c02576 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ [tox] toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic/ envlist = + code-style authentic-py3-dj111-drf39 authentic-py3-dj22-drf39 @@ -106,6 +107,13 @@ commands = ./getlasso3.sh ./authentic2-ctl {posargs:--help} +[testenv:code-style] +skip_install = true +deps = + pre-commit +commands = + pre-commit run black --all-files --show-diff-on-failure + [pytest] filterwarnings = ignore