From patchwork Tue Sep 3 16:10:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21158 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id A6A9DC324C for ; Tue, 3 Sep 2024 16:11:10 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 62E2C634A6; Tue, 3 Sep 2024 18:11:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="OTzRa3vi"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 11B15634A6 for ; Tue, 3 Sep 2024 18:11:09 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:6c8f:1e7a:f75:b6f6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1958916A; Tue, 3 Sep 2024 18:09:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1725379797; bh=2RY8m2fug+NPxeEmCWbkkP5sKJBe9MfIIN74EVqNOPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OTzRa3vieffe+a/NdAHtA7DKgzHpgdBqz++Q1fcUuZ8iUs/TnX2sAWegnKXdEdDd+ bQC4tYv7vwapcYECgYO3Jx44I/e7oFplRp+zbYB5TOWg/ZGiR7AWEYoX0OyMWYflUC uAJpTCA82+/7Z1J6yCc19+1PoXJXv3RxK6N9RQj0= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 1/2] utils: checkstyle: Add a python formatter Date: Tue, 3 Sep 2024 18:10:54 +0200 Message-ID: <20240903161059.246075-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240903161059.246075-1-stefan.klug@ideasonboard.com> References: <20240903161059.246075-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Reporting style issues on python files is great, automatically fixing them is even better. Add a call to autopep8 for python files. This fixes the same issues as the ones reported by pycodestyle. Signed-off-by: Stefan Klug Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- utils/checkstyle.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index c9e41d4149f7..1ee211c3bb9b 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -943,6 +943,21 @@ class IncludeOrderFormatter(Formatter): return '\n'.join(lines) +class Pep8Formatter(Formatter): + patterns = ('*.py',) + + @classmethod + def format(cls, filename, data): + try: + ret = subprocess.run(['autopep8', '--ignore=E501', '-'], + input=data.encode('utf-8'), stdout=subprocess.PIPE) + except FileNotFoundError: + issues.append(StyleIssue(0, None, None, 'Please install autopep8 to format python additions')) + return issues + + return ret.stdout.decode('utf-8') + + class StripTrailingSpaceFormatter(Formatter): patterns = ('*.c', '*.cpp', '*.h', '*.py', 'meson.build') From patchwork Tue Sep 3 16:10:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21159 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 441AAC324C for ; Tue, 3 Sep 2024 16:11:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id DF7D4634CB; Tue, 3 Sep 2024 18:11:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="P2MBeca1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B1000634E9 for ; Tue, 3 Sep 2024 18:11:11 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:6c8f:1e7a:f75:b6f6]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B703B16A; Tue, 3 Sep 2024 18:09:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1725379799; bh=Is49YY0SRWDDRWLkxn1h4o45J/r1xCpByFUCIFOOopY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P2MBeca18SeR+F3xj/dLz19VOSZsv8qjnAJKVUpsTsemHvw1rtp5dFk8GT0/hlKB/ OCZRYkxyMD2fN1n+GtUzLVVjzTTYDk6f2OqGMiSx2R6iag7B7NC7YcyLv37r4el/W2 v9zuXYGIkP9X0Un5kocnoI5tRSJARjQIQMYP3OEs= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v2 2/2] utils: checkstyle: Remove style checker for python pep8 Date: Tue, 3 Sep 2024 18:10:55 +0200 Message-ID: <20240903161059.246075-3-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240903161059.246075-1-stefan.klug@ideasonboard.com> References: <20240903161059.246075-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 Reviewed-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- 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]+):')