{"id":21699,"url":"https://patchwork.libcamera.org/api/1.1/patches/21699/?format=json","web_url":"https://patchwork.libcamera.org/patch/21699/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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-4-laurent.pinchart@ideasonboard.com>","date":"2024-10-18T19:32:45","name":"[3/4] utils: checkstyle.py: Print issues using __str__","commit_ref":"57224387540e008c7f0d440890cce22154c95c5e","pull_url":null,"state":"accepted","archived":false,"hash":"370f5c1ff8dc22d073bf20522de666ec6c259407","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/1.1/people/2/?format=json","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21699/mbox/","series":[{"id":4723,"url":"https://patchwork.libcamera.org/api/1.1/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/21699/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21699/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 5D3BDC32AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 18 Oct 2024 19:33:04 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A90BC65391;\n\tFri, 18 Oct 2024 21:33:03 +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 8D4706538A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 18 Oct 2024 21:32:56 +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 8715521C;\n\tFri, 18 Oct 2024 21:31:12 +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=\"hPO9l+ew\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729279872;\n\tbh=HibV6QN6HFJ32OlNJ2YQbp2Pu7qHJi1MPs3Y6vOalj8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=hPO9l+ewnG25bDCbYeCDueB34D1b9Q068fWHQcnf7REPAS98s50nsF4YW9v3a/GrL\n\tsMm5Vff9JE4YEX6a/NpMb21AAwXLyVoJpPDcxqbU6PJHqtETFBkvxM/AIj1uCVxr9O\n\toLbO/FxVOkRBwyciDcbXy4J0MTreIQe9EBNhLq0k=","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH 3/4] utils: checkstyle.py: Print issues using __str__","Date":"Fri, 18 Oct 2024 22:32:45 +0300","Message-ID":"<20241018193246.805-4-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":"CommitIssue and StyleIssue classes have different string\nrepresentations, which are handled by type-specific print() calls in the\ncode that handles the issues. This requires the user to know which type\nof issue it is dealing with. Simplify that by moving the string\nrepresentation logic to a __str__() method.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n utils/checkstyle.py | 39 +++++++++++++++++++++++----------------\n 1 file changed, 23 insertions(+), 16 deletions(-)","diff":"diff --git a/utils/checkstyle.py b/utils/checkstyle.py\nindex bc0ddfad8743..3f841a54d54a 100755\n--- a/utils/checkstyle.py\n+++ b/utils/checkstyle.py\n@@ -391,6 +391,9 @@ class CommitIssue(object):\n     def __init__(self, msg):\n         self.msg = msg\n \n+    def __str__(self):\n+        return f'{Colours.fg(Colours.Yellow)}{self.msg}{Colours.reset()}'\n+\n \n class HeaderAddChecker(CommitChecker):\n     commit_types = (Commit, StagedChanges, Amendment)\n@@ -592,6 +595,24 @@ class StyleIssue(object):\n         self.line = line\n         self.msg = msg\n \n+    def __str__(self):\n+        s = []\n+        s.append(f'{Colours.fg(Colours.Yellow)}#{self.line_number}: {self.msg}{Colours.reset()}')\n+        if self.line is not None:\n+            s.append(f'{Colours.fg(Colours.Yellow)}+{self.line.rstrip()}{Colours.reset()}')\n+\n+            if self.position is not None:\n+                # Align the position marker by using the original line with\n+                # all characters except for tabs replaced with spaces. This\n+                # ensures proper alignment regardless of how the code is\n+                # indented.\n+                start = self.position[0]\n+                prefix = ''.join([c if c == '\\t' else ' ' for c in self.line[:start]])\n+                length = self.position[1] - start - 1\n+                s.append(f' {prefix}^{\"~\" * length}')\n+\n+        return '\\n'.join(s)\n+\n \n class HexValueChecker(StyleChecker):\n     patterns = ('*.c', '*.cpp', '*.h')\n@@ -936,21 +957,7 @@ def check_file(top_level, commit, filename, checkers):\n     if len(issues):\n         issues = sorted(issues, key=lambda i: i.line_number)\n         for issue in issues:\n-            print('%s#%u: %s%s' % (Colours.fg(Colours.Yellow), issue.line_number,\n-                                   issue.msg, Colours.reset()))\n-            if issue.line is not None:\n-                print('%s+%s%s' % (Colours.fg(Colours.Yellow), issue.line.rstrip(),\n-                                   Colours.reset()))\n-\n-                if issue.position is not None:\n-                    # Align the position marker by using the original line with\n-                    # all characters except for tabs replaced with spaces. This\n-                    # ensures proper alignment regardless of how the code is\n-                    # indented.\n-                    start = issue.position[0]\n-                    prefix = ''.join([c if c == '\\t' else ' ' for c in issue.line[:start]])\n-                    length = issue.position[1] - start - 1\n-                    print(' ' + prefix + '^' + '~' * length)\n+            print(issue)\n \n     return len(formatted_diff) + len(issues)\n \n@@ -967,7 +974,7 @@ def check_style(top_level, commit, checkers):\n     # Apply the commit checkers first.\n     for checker in CommitChecker.instances(commit, checkers):\n         for issue in checker.check(commit, top_level):\n-            print('%s%s%s' % (Colours.fg(Colours.Yellow), issue.msg, Colours.reset()))\n+            print(issue)\n             issues += 1\n \n     # Filter out files we have no checker for.\n","prefixes":["3/4"]}