[{"id":31852,"web_url":"https://patchwork.libcamera.org/comment/31852/","msgid":"<172951476049.3674438.6470965657682041876@ping.linuxembedded.co.uk>","date":"2024-10-21T12:46:00","subject":"Re: [PATCH 2/4] utils: checkstyle.py: Turn check() into a class\n\tmethod for all checkers","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart (2024-10-18 20:32:44)\n> The check() method of StyleChecker subclasses are instance methods,\n> while CommitChecker subclasses use class methods. This makes unified\n> handling of checkers more complicated. Turn the StyleChecker check()\n> method into a class method, passing it the contents to be checked\n> directly.\n> \n> While at it, fix two style issues reported by checkstyle.py.\n\nHow very self-referencial ;-)\n\nLGTM\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  utils/checkstyle.py | 48 +++++++++++++++------------------------------\n>  1 file changed, 16 insertions(+), 32 deletions(-)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index 1de518953dcd..bc0ddfad8743 100755\n> --- a/utils/checkstyle.py\n> +++ b/utils/checkstyle.py\n> @@ -598,15 +598,12 @@ class HexValueChecker(StyleChecker):\n>  \n>      regex = re.compile(r'\\b0[xX][0-9a-fA-F]+\\b')\n>  \n> -    def __init__(self, content):\n> -        super().__init__()\n> -        self.__content = content\n> -\n> -    def check(self, line_numbers):\n> +    @classmethod\n> +    def check(cls, content, line_numbers):\n>          issues = []\n>  \n>          for line_number in line_numbers:\n> -            line = self.__content[line_number - 1]\n> +            line = content[line_number - 1]\n>              match = HexValueChecker.regex.search(line)\n>              if not match:\n>                  continue\n> @@ -630,15 +627,12 @@ class IncludeChecker(StyleChecker):\n>                 'cwchar', 'cwctype', 'math.h')\n>      include_regex = re.compile(r'^#include <([a-z.]*)>')\n>  \n> -    def __init__(self, content):\n> -        super().__init__()\n> -        self.__content = content\n> -\n> -    def check(self, line_numbers):\n> +    @classmethod\n> +    def check(self, content, line_numbers):\n>          issues = []\n>  \n>          for line_number in line_numbers:\n> -            line = self.__content[line_number - 1]\n> +            line = content[line_number - 1]\n>              match = IncludeChecker.include_regex.match(line)\n>              if not match:\n>                  continue\n> @@ -664,14 +658,11 @@ class LogCategoryChecker(StyleChecker):\n>      log_regex = re.compile(r'\\bLOG\\((Debug|Info|Warning|Error|Fatal)\\)')\n>      patterns = ('*.cpp',)\n>  \n> -    def __init__(self, content):\n> -        super().__init__()\n> -        self.__content = content\n> -\n> -    def check(self, line_numbers):\n> +    @classmethod\n> +    def check(cls, content, line_numbers):\n>          issues = []\n>          for line_number in line_numbers:\n> -            line = self.__content[line_number-1]\n> +            line = content[line_number - 1]\n>              match = LogCategoryChecker.log_regex.search(line)\n>              if not match:\n>                  continue\n> @@ -685,14 +676,11 @@ class LogCategoryChecker(StyleChecker):\n>  class MesonChecker(StyleChecker):\n>      patterns = ('meson.build',)\n>  \n> -    def __init__(self, content):\n> -        super().__init__()\n> -        self.__content = content\n> -\n> -    def check(self, line_numbers):\n> +    @classmethod\n> +    def check(cls, content, line_numbers):\n>          issues = []\n>          for line_number in line_numbers:\n> -            line = self.__content[line_number-1]\n> +            line = content[line_number - 1]\n>              pos = line.find('\\t')\n>              if pos != -1:\n>                  issues.append(StyleIssue(line_number, [pos, pos], line,\n> @@ -704,13 +692,10 @@ class ShellChecker(StyleChecker):\n>      patterns = ('*.sh',)\n>      results_line_regex = re.compile(r'In - line ([0-9]+):')\n>  \n> -    def __init__(self, content):\n> -        super().__init__()\n> -        self.__content = content\n> -\n> -    def check(self, line_numbers):\n> +    @classmethod\n> +    def check(cls, content, line_numbers):\n>          issues = []\n> -        data = ''.join(self.__content).encode('utf-8')\n> +        data = ''.join(content).encode('utf-8')\n>  \n>          try:\n>              ret = subprocess.run(['shellcheck', '-Cnever', '-'],\n> @@ -934,9 +919,8 @@ def check_file(top_level, commit, filename, checkers):\n>      # Check for code issues not related to formatting.\n>      issues = []\n>      for checker in StyleChecker.instances(filename, checkers):\n> -        checker = checker(after)\n>          for hunk in commit_diff:\n> -            issues += checker.check(hunk.side('to').touched)\n> +            issues += checker.check(after, hunk.side('to').touched)\n>  \n>      # Print the detected issues.\n>      if len(issues) == 0 and len(formatted_diff) == 0:\n> -- \n> Regards,\n> \n> Laurent Pinchart\n>","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 1F54FC3304\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Oct 2024 12:46:06 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 26F4465393;\n\tMon, 21 Oct 2024 14:46:05 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id EA9606538B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Oct 2024 14:46:02 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id DA92E316;\n\tMon, 21 Oct 2024 14:44:16 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"iAyyiKFm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729514656;\n\tbh=ldHSLCdo8RYMZ/T1m2EDXEy9XCZn2TVECbF6Db6WcQc=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=iAyyiKFm5mDEHOV2xWvgKZC3EdGzCaOll9Gs01qZEsilQa1oUMF0C3nwG84Q8FqNW\n\twSjQCmyuQlB1gZ2P1b4HDDeEGhDuIvRY7WucSOFd2o83rFSlOAsmZyUxl+etnOLeYe\n\tjPPct7LCNzc3wQdazF+ozFQ1fJE+hdMaRWD18PBg=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241018193246.805-3-laurent.pinchart@ideasonboard.com>","References":"<20241018193246.805-1-laurent.pinchart@ideasonboard.com>\n\t<20241018193246.805-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH 2/4] utils: checkstyle.py: Turn check() into a class\n\tmethod for all checkers","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 21 Oct 2024 13:46:00 +0100","Message-ID":"<172951476049.3674438.6470965657682041876@ping.linuxembedded.co.uk>","User-Agent":"alot/0.10","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]