{"id":21698,"url":"https://patchwork.libcamera.org/api/patches/21698/?format=json","web_url":"https://patchwork.libcamera.org/patch/21698/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20241018193246.805-3-laurent.pinchart@ideasonboard.com>","date":"2024-10-18T19:32:44","name":"[2/4] utils: checkstyle.py: Turn check() into a class method for all checkers","commit_ref":"b488a862dfd8b81f7aeba00342af0e15e60b9fcd","pull_url":null,"state":"accepted","archived":false,"hash":"4888d8efa1da6eb1f1fcbc7cb44fb678a2991cb9","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21698/mbox/","series":[{"id":4723,"url":"https://patchwork.libcamera.org/api/series/4723/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4723","date":"2024-10-18T19:32:42","name":"utils: checkstyle.py: Improve dependency handling","version":1,"mbox":"https://patchwork.libcamera.org/series/4723/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21698/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21698/checks/","tags":{},"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 99033C32AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Oct 2024 19:33:02 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1E0DB65394;\n\tFri, 18 Oct 2024 21:33:02 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 6ADBE633C6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Oct 2024 21:32:55 +0200 (CEST)","from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi\n\t[81.175.209.231])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id EFF6C21C;\n\tFri, 18 Oct 2024 21:31:10 +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=\"E3geKud4\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729279871;\n\tbh=sRWu18G/T97g8sTHlk8+S//JIV1jOROF4ut9yODdjGY=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=E3geKud4WM6LQ4Irkx5/39I0HDjMQ+DT6veRQpgCuyJs396bCrNVmNLMkF79i3nNs\n\tLuF/0XnXaoLw2bE0iZoI59J1STg34bt/ldmZcIR5Rf933QlvU9wlNhopJcZsGP5HfH\n\tuLSZBPWOZDm6nfLDMfWQlLeEuHkuCws5keOYKvTU=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH 2/4] utils: checkstyle.py: Turn check() into a class method\n\tfor all checkers","Date":"Fri, 18 Oct 2024 22:32:44 +0300","Message-ID":"<20241018193246.805-3-laurent.pinchart@ideasonboard.com>","X-Mailer":"git-send-email 2.45.2","In-Reply-To":"<20241018193246.805-1-laurent.pinchart@ideasonboard.com>","References":"<20241018193246.805-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","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>"},"content":"The check() method of StyleChecker subclasses are instance methods,\nwhile CommitChecker subclasses use class methods. This makes unified\nhandling of checkers more complicated. Turn the StyleChecker check()\nmethod into a class method, passing it the contents to be checked\ndirectly.\n\nWhile at it, fix two style issues reported by checkstyle.py.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/checkstyle.py | 48 +++++++++++++++------------------------------\n 1 file changed, 16 insertions(+), 32 deletions(-)","diff":"diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex 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","prefixes":["2/4"]}