[v2,2/2] utils: checkstyle: Remove style checker for python pep8
diff mbox series

Message ID 20240903161059.246075-3-stefan.klug@ideasonboard.com
State Accepted
Commit 8161018b9b2a161b83072d5ddec7658079850c21
Headers show
Series
  • Python improvements to checkstyle.py
Related show

Commit Message

Stefan Klug Sept. 3, 2024, 4:10 p.m. UTC
The issues detected and fixed by autopep8 are the same as the ones
detected by pycodestyle. As the formatter runs unconditionally we can
remove the checker.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 utils/checkstyle.py | 33 ---------------------------------
 1 file changed, 33 deletions(-)

Comments

Laurent Pinchart Sept. 3, 2024, 6:28 p.m. UTC | #1
Hi Stefan,

Thank you for the patch.

On Tue, Sep 03, 2024 at 06:10:55PM +0200, Stefan Klug wrote:
> The issues detected and fixed by autopep8 are the same as the ones
> detected by pycodestyle. As the formatter runs unconditionally we can
> remove the checker.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  utils/checkstyle.py | 33 ---------------------------------
>  1 file changed, 33 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 1ee211c3bb9b..ab89c0a14fab 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]+):')
Kieran Bingham Sept. 4, 2024, 9:59 a.m. UTC | #2
Quoting Stefan Klug (2024-09-03 17:10:55)
> The issues detected and fixed by autopep8 are the same as the ones
> detected by pycodestyle. As the formatter runs unconditionally we can
> remove the checker.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> ---
>  utils/checkstyle.py | 33 ---------------------------------
>  1 file changed, 33 deletions(-)
> 
> diff --git a/utils/checkstyle.py b/utils/checkstyle.py
> index 1ee211c3bb9b..ab89c0a14fab 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))

I like how the formatter is so much simpler as it's all just 'handled'.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> -
> -        return issues
> -
> -
>  class ShellChecker(StyleChecker):
>      patterns = ('*.sh',)
>      results_line_regex = re.compile(r'In - line ([0-9]+):')
> -- 
> 2.43.0
>

Patch
diff mbox series

diff --git a/utils/checkstyle.py b/utils/checkstyle.py
index 1ee211c3bb9b..ab89c0a14fab 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]+):')