summaryrefslogtreecommitdiff
path: root/utils/checkstyle.py
diff options
context:
space:
mode:
Diffstat (limited to 'utils/checkstyle.py')
-rwxr-xr-xutils/checkstyle.py48
1 files changed, 15 insertions, 33 deletions
diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index c9e41d41..ab89c0a1 100755
--- a/utils/checkstyle.py
+++ b/utils/checkstyle.py
@@ -709,39 +709,6 @@ class MesonChecker(StyleChecker):
return issues
-class Pep8Checker(StyleChecker):
- patterns = ('*.py',)
- results_regex = re.compile(r'stdin:([0-9]+):([0-9]+)(.*)')
-
- def __init__(self, content):
- super().__init__()
- self.__content = content
-
- def check(self, line_numbers):
- issues = []
- data = ''.join(self.__content).encode('utf-8')
-
- try:
- ret = subprocess.run(['pycodestyle', '--ignore=E501', '-'],
- input=data, stdout=subprocess.PIPE)
- except FileNotFoundError:
- issues.append(StyleIssue(0, None, None, 'Please install pycodestyle to validate python additions'))
- return issues
-
- results = ret.stdout.decode('utf-8').splitlines()
- for item in results:
- search = re.search(Pep8Checker.results_regex, item)
- line_number = int(search.group(1))
- position = int(search.group(2))
- msg = search.group(3)
-
- if line_number in line_numbers:
- line = self.__content[line_number - 1]
- issues.append(StyleIssue(line_number, None, line, msg))
-
- return issues
-
-
class ShellChecker(StyleChecker):
patterns = ('*.sh',)
results_line_regex = re.compile(r'In - line ([0-9]+):')
@@ -943,6 +910,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')