From ba4f47f580df5265f202ad54d12177a87f90354e Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 12 Oct 2025 00:00:29 +0900 Subject: [PATCH] Use pre-commit for pep8 checks pre-commit was introduced in several repos and is known to be useful. It allows us to easily add more checks. Change-Id: Ic551481a98d9c3f2e5aaf430108bf4e3d2501ebf Signed-off-by: Takashi Kajinami --- .pre-commit-config.yaml | 24 +++++++++++++++++++ HACKING.rst | 9 ++++--- etc/logging.conf.sample | 2 +- .../javascript/send_message/zaqar_sample.js | 2 +- .../receive_message/SampleZaqarServlet.java | 2 +- .../nodejs/receive_message/zaqar_sample.js | 2 +- test-requirements.txt | 3 +-- tox.ini | 6 ++--- 8 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..296d46323 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: trailing-whitespace + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + - id: fix-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://opendev.org/openstack/hacking + rev: 7.0.0 + hooks: + - id: hacking + additional_dependencies: [] + exclude: '^(doc|releasenotes|tools)/.*$' + - repo: https://github.com/PyCQA/doc8 + rev: v2.0.0 + hooks: + - id: doc8 diff --git a/HACKING.rst b/HACKING.rst index 1970188de..ad0ef3aa7 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -31,8 +31,10 @@ Comments Identifiers ----------- -- Don't use single characters in identifiers except in trivial loop variables and mathematical algorithms. -- Avoid abbreviations, especially if they are ambiguous or their meaning would not be immediately clear to the casual reader or newcomer. +- Don't use single characters in identifiers except in trivial loop variables + and mathematical algorithms. +- Avoid abbreviations, especially if they are ambiguous or their meaning would + not be immediately clear to the casual reader or newcomer. Wrapping -------- @@ -68,7 +70,8 @@ Example:: Imports ------- -- Classes and functions may be hoisted into a package namespace, via __init__ files, with some discretion. +- Classes and functions may be hoisted into a package namespace, via + __init__ files, with some discretion. More Import Examples -------------------- diff --git a/etc/logging.conf.sample b/etc/logging.conf.sample index 54d75b190..83a704069 100644 --- a/etc/logging.conf.sample +++ b/etc/logging.conf.sample @@ -46,4 +46,4 @@ format=%(asctime)s %(levelname)s %(message)s format=(%(name)s): %(asctime)s %(levelname)s %(message)s [formatter_debug] -format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s +format=(%(name)s): %(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s diff --git a/samples/javascript/send_message/zaqar_sample.js b/samples/javascript/send_message/zaqar_sample.js index 75141b3e7..db77ed7a3 100644 --- a/samples/javascript/send_message/zaqar_sample.js +++ b/samples/javascript/send_message/zaqar_sample.js @@ -17,7 +17,7 @@ ws.onopen = () => { ws.send('{"action": "authenticate", "headers": {"X-Auth-Token": \ "8444886dd9b04a1b87ddb502b508261c", "X-Project-ID": \ "7530fad032ca431e9dc8ed4a5de5d99c"}}'); // refer to bug #1553398 - + ws.send('{"action": "message_post", "body": {"messages": [{"body": \ "Zaqar Sample"}], "queue_name": "SampleQueue"}, "headers": \ {"Client-ID": "355186cd-d1e8-4108-a3ac-a2183697232a", "X-Project-ID": \ diff --git a/samples/jaxrs/receive_message/SampleZaqarServlet.java b/samples/jaxrs/receive_message/SampleZaqarServlet.java index 21c83fcef..77d46ae36 100644 --- a/samples/jaxrs/receive_message/SampleZaqarServlet.java +++ b/samples/jaxrs/receive_message/SampleZaqarServlet.java @@ -41,7 +41,7 @@ public final class SampleZaqarServlet extends HttpServlet { headers.putSingle("X-Auth-Token", "8444886dd9b04a1b87ddb502b508261c"); - headers.putSingle("X-Project-Id", "7530fad032ca431e9dc8ed4a5de5d99c"); + headers.putSingle("X-Project-Id", "7530fad032ca431e9dc8ed4a5de5d99c"); final Response res = client .target("http://localhost:8888/v2/queues/SampleQueue/claims") diff --git a/samples/nodejs/receive_message/zaqar_sample.js b/samples/nodejs/receive_message/zaqar_sample.js index 0c8b87d9a..056eb5aab 100644 --- a/samples/nodejs/receive_message/zaqar_sample.js +++ b/samples/nodejs/receive_message/zaqar_sample.js @@ -17,7 +17,7 @@ const ws = new WebSocket('ws://localhost:9000'); ws.on('message', (data, flags) => { const msg = JSON.parse(data); - + if (msg.body.messages) console.log(msg.body.messages[0].body); diff --git a/test-requirements.txt b/test-requirements.txt index 1409798c0..129cc2006 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,4 +1,4 @@ -hacking>=6.1.0,<6.2.0 # Apache-2.0 +hacking>=7.0.0,<7.1.0 # Apache-2.0 # Backends redis>=3.4.0 # MIT @@ -11,7 +11,6 @@ PyMySQL>=0.8.0 # MIT License coverage!=4.4,>=4.0 # Apache-2.0 cryptography>=2.7 # BSD/Apache-2.0 ddt>=1.0.1 # MIT -doc8>=0.8.1 # Apache-2.0 Pygments>=2.2.0 # BSD license fixtures>=3.0.0 # Apache-2.0/BSD diff --git a/tox.ini b/tox.ini index ffdb5802f..7d189bd8c 100644 --- a/tox.ini +++ b/tox.ini @@ -25,9 +25,10 @@ setenv = OS_TEST_PATH=./zaqar/tests/functional [testenv:pep8] +deps = + pre-commit commands = - doc8 doc/source - flake8 + pre-commit run -a [testenv:genconfig] commands = @@ -80,7 +81,6 @@ deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/master} -r{toxinidir}/doc/requirements.txt commands = - doc8 releasenotes/source releasenotes/notes sphinx-build -a -E -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html [flake8]