From patchwork Mon Jun 12 22:47:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 18728 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 784FAC31E9 for ; Mon, 12 Jun 2023 22:47:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4C9716289F; Tue, 13 Jun 2023 00:47:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686610076; bh=pFFY84X4S/spKigWytzPQVbkgxCjjLhWG9Rj+tMYnds=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=ick64gzLzY4S35vLNuOcxy6YnGu6AbS5cmt3rUcmvHcunw1u+AY1zclfc1M6mJ+Kx azw9xeVNe14B2PQzpaMtuQze4vdA9otFR8sUkLCH8F2KHGjXmcj4CGWkgDOqc1T8dU 5mfwEfveHwUx6HCqM0CqbDJli9v5SJpNyBvP3uJdW/TMr/0pcctsVUwzm57utFPZ5g LE6bsnz6ffBD0wnp5H59EmRQnLKhNKIHB/sV7kreW33cfsS+FowRDVqk+SsCJ4TU8n FItGbiBJzpH+VekpiVDO8e/7GbIxKbi6+7U25ZIbgfr59GsUH2AKUuz1hSjjPbHE3F TDh6ysZfK7jsg== 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 9D51F6020C for ; Tue, 13 Jun 2023 00:47:54 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="mSJjXB70"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CF9B4D80 for ; Tue, 13 Jun 2023 00:47:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686610045; bh=pFFY84X4S/spKigWytzPQVbkgxCjjLhWG9Rj+tMYnds=; h=From:To:Subject:Date:In-Reply-To:References:From; b=mSJjXB70M5gWssCOmrC7fcJQVDnY0QtgqiMJDHKcYoRsC10vLZru1q08qFvbRXCJr FckUDDbxG1LFc9ex/LtiILTsKj1kixM48OwG/397+1jFkntbPEL58oGnemjMW/oJBb c/HRfhPhkvw7A51sUp7f2BqMb6eBYSn7L8SbzJog= To: libcamera-devel@lists.libcamera.org Date: Tue, 13 Jun 2023 01:47:49 +0300 Message-Id: <20230612224751.4437-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230612224751.4437-1-laurent.pinchart@ideasonboard.com> References: <20230612224751.4437-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/4] utils: checkstyle: Support running checkers selectively 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: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" During development of the checkstyle.py script, it can be useful to run only a subset of the checker. Add the ability to do so with a '--checkers' command line argument. Signed-off-by: Laurent Pinchart Reviewed-by: Mattijs Korpershoek Reviewed-by: Kieran Bingham --- utils/checkstyle.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 7da888d8c365..3104acfa2065 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -301,8 +301,10 @@ class CommitChecker(metaclass=ClassRegistry): # Class methods # @classmethod - def checkers(cls): + def checkers(cls, names): for checker in cls.subclasses: + if names and checker.__name__ not in names: + continue yield checker @@ -436,8 +438,10 @@ class StyleChecker(metaclass=ClassRegistry): # Class methods # @classmethod - def checkers(cls, filename): + def checkers(cls, filename, names): for checker in cls.subclasses: + if names and checker.__name__ not in names: + continue if checker.supports(filename): yield checker @@ -617,8 +621,10 @@ class Formatter(metaclass=ClassRegistry): # Class methods # @classmethod - def formatters(cls, filename): + def formatters(cls, filename, names): for formatter in cls.subclasses: + if names and formatter.__name__ not in names: + continue if formatter.supports(filename): yield formatter @@ -780,7 +786,7 @@ class StripTrailingSpaceFormatter(Formatter): # Style checking # -def check_file(top_level, commit, filename): +def check_file(top_level, commit, filename, checkers): # Extract the line numbers touched by the commit. commit_diff = commit.get_diff(top_level, filename) @@ -797,7 +803,7 @@ def check_file(top_level, commit, filename): after = commit.get_file(filename) formatted = after - for formatter in Formatter.formatters(filename): + for formatter in Formatter.formatters(filename, checkers): formatted = formatter.format(filename, formatted) after = after.splitlines(True) @@ -811,7 +817,7 @@ def check_file(top_level, commit, filename): # Check for code issues not related to formatting. issues = [] - for checker in StyleChecker.checkers(filename): + for checker in StyleChecker.checkers(filename, checkers): checker = checker(after) for hunk in commit_diff: issues += checker.check(hunk.side('to').touched) @@ -839,7 +845,7 @@ def check_file(top_level, commit, filename): return len(formatted_diff) + len(issues) -def check_style(top_level, commit): +def check_style(top_level, commit, checkers): separator = '-' * len(commit.title) print(separator) print(commit.title) @@ -848,7 +854,7 @@ def check_style(top_level, commit): issues = 0 # Apply the commit checkers first. - for checker in CommitChecker.checkers(): + for checker in CommitChecker.checkers(checkers): for issue in checker.check(commit, top_level): print('%s%s%s' % (Colours.fg(Colours.Yellow), issue.msg, Colours.reset())) issues += 1 @@ -860,7 +866,7 @@ def check_style(top_level, commit): files = [f for f in commit.files() if len([p for p in patterns if fnmatch.fnmatch(os.path.basename(f), p)])] for f in files: - issues += check_file(top_level, commit, f) + issues += check_file(top_level, commit, f, checkers) if issues == 0: print('No issue detected') @@ -910,6 +916,8 @@ def main(argv): # Parse command line arguments parser = argparse.ArgumentParser() + parser.add_argument('--checkers', '-c', type=str, + help='Specify which checkers to run as a comma-separated list. Defaults to all checkers') parser.add_argument('--staged', '-s', action='store_true', help='Include the changes in the index. Defaults to False') parser.add_argument('--amend', '-a', action='store_true', @@ -918,6 +926,9 @@ def main(argv): help='Revision range (as defined by git rev-parse). Defaults to HEAD if not specified.') args = parser.parse_args(argv[1:]) + if args.checkers: + args.checkers = args.checkers.split(',') + # Check for required dependencies. for command, mandatory in dependencies.items(): found = shutil.which(command) @@ -951,7 +962,7 @@ def main(argv): issues = 0 for commit in commits: - issues += check_style(top_level, commit) + issues += check_style(top_level, commit, args.checkers) print('') if issues: