[{"id":31853,"web_url":"https://patchwork.libcamera.org/comment/31853/","msgid":"<172951493980.3674438.5881248754936000190@ping.linuxembedded.co.uk>","date":"2024-10-21T12:48:59","subject":"Re: [PATCH 3/4] utils: checkstyle.py: Print issues using __str__","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:45)\n> CommitIssue and StyleIssue classes have different string\n> representations, which are handled by type-specific print() calls in the\n> code that handles the issues. This requires the user to know which type\n> of issue it is dealing with. Simplify that by moving the string\n> representation logic to a __str__() method.\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> ---\n>  utils/checkstyle.py | 39 +++++++++++++++++++++++----------------\n>  1 file changed, 23 insertions(+), 16 deletions(-)\n> \n> diff --git a/utils/checkstyle.py b/utils/checkstyle.py\n> index 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> -- \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 B331DC32A3\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 21 Oct 2024 12:49:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BADD765395;\n\tMon, 21 Oct 2024 14:49:04 +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 68A9965391\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 21 Oct 2024 14:49:03 +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 6B57C316;\n\tMon, 21 Oct 2024 14:47:17 +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=\"tCXuM4Db\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1729514837;\n\tbh=dDBETwAg+EzTarMcRdCKfwEPmZkYMS9xZvZB/vlZnK0=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=tCXuM4Db1GSR1VFmKGzLvzV7ofsMq3Cos5GLu79YJHrrgh9V6pFFpI3+AxZDjKbmz\n\tY9JJLRuJJNoAmwbjVQMIxlsfNZfWF6OWyRjW5bm9C08qMYuRRPYZpEhouSOv1I/8uK\n\tTRGNo/A2Az0QPadFg3bc9bjvoye2NahfX0r8ubug=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20241018193246.805-4-laurent.pinchart@ideasonboard.com>","References":"<20241018193246.805-1-laurent.pinchart@ideasonboard.com>\n\t<20241018193246.805-4-laurent.pinchart@ideasonboard.com>","Subject":"Re: [PATCH 3/4] utils: checkstyle.py: Print issues using __str__","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:48:59 +0100","Message-ID":"<172951493980.3674438.5881248754936000190@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>"}}]