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>
This commit is contained in:
parent
b318101ada
commit
8ffaf376bb
1 changed files with 15 additions and 0 deletions
|
@ -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')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue