summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-09-03 18:10:54 +0200
committerStefan Klug <stefan.klug@ideasonboard.com>2024-09-04 17:22:36 +0200
commit8ffaf376bb53f6c4433e1fda4078f66dc5e69af5 (patch)
tree2202f264ea6706f74e32629f1979e0230a1e1191 /utils
parentb318101ada9ccd2c8b53b8c7a1436e84fc157e04 (diff)
utils: checkstyle: Add a python formatter
Reporting style issues on python files is great, automatically fixing them is even better. Add a call to autopep8 for python files. This fixes the same issues as the ones reported by pycodestyle. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils')
-rwxr-xr-xutils/checkstyle.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index c9e41d41..1ee211c3 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -943,6 +943,21 @@ class IncludeOrderFormatter(Formatter):
return '\n'.join(lines)
+class Pep8Formatter(Formatter):
+ patterns = ('*.py',)
+
+ @classmethod
+ def format(cls, filename, data):
+ try:
+ ret = subprocess.run(['autopep8', '--ignore=E501', '-'],
+ input=data.encode('utf-8'), stdout=subprocess.PIPE)
+ except FileNotFoundError:
+ issues.append(StyleIssue(0, None, None, 'Please install autopep8 to format python additions'))
+ return issues
+
+ return ret.stdout.decode('utf-8')
+
+
class StripTrailingSpaceFormatter(Formatter):
patterns = ('*.c', '*.cpp', '*.h', '*.py', 'meson.build')