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')