Add checkpatch.py
RFC PATCH 1/1 Add checkpatch.py
---
Peter recently posted a series to update the kernel-doc perl script with the new python one from the upstream kernel tree. I mentioned on IRC I had a personal/private checkpatch python script and was encouraged to post this here on the list.
While there's nothing immediately wrong with checkpatch.pl, its design makes it harder to implement new checks, refactor code, and because of its custom nature it's been nigh impossible for years to sync it with the kernel's original implementation. So there's no particular attachment to staying with a perl script of many thousands of lines.
This patch introduces a script/checkpatch.py script that uses a script/libcheckpatch python library that doesn't use any dependencies.
There's a proof of concept for unittests:
python3 -m unittest -v scripts/libcheckpatch/tests.py
The CLI use is/should be identical to checkpatch.pl; just substitute the filename extension in your invocations. The output format(s) are also identical.
All checks that are in the original perl script and are missing are annotated with a # TODO comment. A grep TODO | wc -l says it's about 60 at the time of writing.
This is an incomplete replacement for checkpatch.pl, so for this RFC I look forward to high-level architecture and design comments.
NB: Python's import resolution logic makes it difficult to split checks for different kinds of files into separate modules, unfortunately. I hit "circular import" errors a lot.
--- .b4-config | 4 +- MAINTAINERS | 2 +- scripts/checkpatch.py | 9 + scripts/libcheckpatch/__init__.py | 388 +++++++++++++++++++++++++++ scripts/libcheckpatch/checks.py | 535 ++++++++++++++++++++++++++++++++++++++ scripts/libcheckpatch/output.py | 89 +++++++ scripts/libcheckpatch/patch.py | 330 +++++++++++++++++++++++ scripts/libcheckpatch/tests.py | 277 ++++++++++++++++++++ 8 files changed, 1631 insertions(+), 3 deletions(-)
.b4-config +2 -2
@@ -7,7 +7,7 @@ send-series-to = [email protected] send-auto-to-cmd = echo send-auto-cc-cmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback - am-perpatch-check-cmd = scripts/checkpatch.pl -q --terse --no-summary --mailback - - prep-perpatch-check-cmd = scripts/checkpatch.pl -q --terse --no-summary --mailback - + am-perpatch-check-cmd = scripts/checkpatch.py -q --terse --no-summary --mailback - + prep-perpatch-check-cmd = scripts/checkpatch.py -q --terse --no-summary --mailback - searchmask = https://lore.kernel.org/qemu-devel/?x=m&t=1&q=%s linkmask = https://lore.kernel.org/qemu-devel/%s
MAINTAINERS +1 -1
@@ -3585,7 +3585,7 @@ F: include/system/spdm-socket.h Checkpatch S: Odd Fixes -F: scripts/checkpatch.pl +F: scripts/checkpatch.p[ly] Migration M: Peter Xu <[email protected]>
scripts/checkpatch.py new file +9 -0
@@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +import sys + +from libcheckpatch import main + +if __name__ == "__main__": + sys.exit(main())
scripts/libcheckpatch/__init__.py new file +388 -0
388 lines not on this page · raw message
scripts/libcheckpatch/checks.py new file +535 -0
535 lines not on this page · raw message
scripts/libcheckpatch/output.py new file +89 -0
89 lines not on this page · raw message
scripts/libcheckpatch/patch.py new file +330 -0
330 lines not on this page · raw message
scripts/libcheckpatch/tests.py new file +277 -0
277 lines not on this page · raw message
---
base-commit: 5836af0783213b9355a6bbf85d9e6bc4c9c9363f
change-id: 20250806-checkpatch-py-9ed21d18c99e
--
γαῖα πυρί μιχθήτω