From patchwork Mon Sep 30 12:39:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 1990954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WOBOEFHM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHLLV25J9z1xtM for ; Mon, 30 Sep 2024 22:42:10 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 5BBF080C1C; Mon, 30 Sep 2024 12:42:08 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id iWPfyRpitzVi; Mon, 30 Sep 2024 12:42:07 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 3253E80B8C Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WOBOEFHM Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 3253E80B8C; Mon, 30 Sep 2024 12:42:07 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EB268C002B; Mon, 30 Sep 2024 12:42:06 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 73432C002A for ; Mon, 30 Sep 2024 12:42:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 4CC3B60590 for ; Mon, 30 Sep 2024 12:42:05 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 0NXrHZn9GfWE for ; Mon, 30 Sep 2024 12:42:04 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=echaudro@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 4EF966066F Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 4EF966066F Authentication-Results: smtp3.osuosl.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WOBOEFHM Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp3.osuosl.org (Postfix) with ESMTPS id 4EF966066F for ; Mon, 30 Sep 2024 12:42:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727700122; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KiPogzSE6QUssxzB3Q41++6P8sJhtbN+qg2eXcaK0Wg=; b=WOBOEFHMysvRbB8gtRj0PEsE4dzAUbHCz+SYwh0RFRs3XwnPYjqXxVfhiuZFcD55EpyWek ZhMkS/x9/x9o0dVudY+Wz0YuiQ0ACoWB8Y/RKnJD364vMe1F8DrjrRg3XdpVlzc5YFbWz/ TcRB50uLPmMlsmnQAwwA97IfRthoBWY= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-74-f_hDQTu2OQCjr_8p9Gykjg-1; Mon, 30 Sep 2024 08:41:59 -0400 X-MC-Unique: f_hDQTu2OQCjr_8p9Gykjg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5003619772C9; Mon, 30 Sep 2024 12:41:58 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.194.95]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1C421195419F; Mon, 30 Sep 2024 12:41:56 +0000 (UTC) From: Eelco Chaudron To: dev@openvswitch.org Date: Mon, 30 Sep 2024 14:39:58 +0200 Message-ID: <64c06b55bb51ea5e370c46d2beb29c9c1252905c.1727699998.git.echaudro@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v3] checkpatch: Add new check-authors-file option to checkpatch.py. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This patch adds a new option, --check-authors-file, to the checkpatch tool to help OVS maintainers check for missing authors in the AUTHORS.rst file. Signed-off-by: Eelco Chaudron --- v3: - Also include co-authors in the check. - Only report the end, when all patches are checked. - Fixed spelling mistake. - Determine git root directory for AUTHORS.rst location. --- utilities/checkpatch.py | 61 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 742a0bc47..31b791d8f 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -28,12 +28,14 @@ __errors = 0 __warnings = 0 empty_return_check_state = 0 print_file_name = None +check_authors_file = False checking_file = False total_line = 0 colors = False spellcheck = False quiet = False spell_check_dict = None +missing_authors = [] def open_spell_check_dict(): @@ -860,9 +862,41 @@ def run_subject_checks(subject, spellcheck=False): return warnings +def get_top_directory(): + with os.popen('git rev-parse --show-toplevel') as pipe: + path = pipe.read() + + if path: + return path.strip() + + return "." + + +def do_authors_exist(authors): + authors = list(set(authors)) + missing_authors = [] + + try: + with open(get_top_directory() + "/AUTHORS.rst", "r") as file: + file_content = file.read() + for author in authors: + m = re.search(r'<(.*?)>', author) + if not m: + continue + pattern = r'\b' + re.escape(m.group(1)) + r'\b' + if re.search(pattern, file_content) is None: + missing_authors.append(author) + + except FileNotFoundError: + print_error("Could not open AUTHORS.rst in '%s/'!" % + get_top_directory()) + + return missing_authors + + def ovs_checkpatch_parse(text, filename, author=None, committer=None): global print_file_name, total_line, checking_file, \ - empty_return_check_state + empty_return_check_state, missing_authors PARSE_STATE_HEADING = 0 PARSE_STATE_DIFF_HEADER = 1 @@ -977,6 +1011,11 @@ def ovs_checkpatch_parse(text, filename, author=None, committer=None): "who are not authors or co-authors or " "committers: %s" % ", ".join(extra_sigs)) + + if check_authors_file: + missing_authors = do_authors_exist(missing_authors + + co_authors + [author]) + elif is_committer.match(line): committer = is_committer.match(line).group(2) elif is_author.match(line): @@ -1067,6 +1106,8 @@ Input options: Check options: -h|--help This help message +-a|--check-authors-file Check AUTHORS file for existence of the authors. + Should be used by commiters only! -b|--skip-block-whitespace Skips the if/while/for whitespace tests -l|--skip-leading-whitespace Skips the leading whitespace test -q|--quiet Only print error and warning information @@ -1089,6 +1130,16 @@ def ovs_checkpatch_print_result(): print("Lines checked: %d, no obvious problems found\n" % (total_line)) +def ovs_checkpatch_print_missing_authors(): + if missing_authors: + if len(missing_authors) == 1: + print_warning("Author '%s' is not in the AUTHORS.rst file!" \ + % missing_authors[0]) + else: + print_warning("Authors '%s' are not in the AUTHORS.rst file!" \ + % ', '.join(missing_authors)) + + def ovs_checkpatch_file(filename): try: mail = email.message_from_file(open(filename, 'r', encoding='utf8')) @@ -1116,6 +1167,7 @@ def ovs_checkpatch_file(filename): result = True ovs_checkpatch_print_result() + ovs_checkpatch_print_missing_authors() return result @@ -1138,9 +1190,10 @@ if __name__ == '__main__': sys.argv[1:]) n_patches = int(numeric_options[-1][1:]) if numeric_options else 0 - optlist, args = getopt.getopt(args, 'bhlstfSq', + optlist, args = getopt.getopt(args, 'abhlstfSq', ["check-file", "help", + "check-authors-file", "skip-block-whitespace", "skip-leading-whitespace", "skip-signoff-lines", @@ -1157,6 +1210,8 @@ if __name__ == '__main__': if o in ("-h", "--help"): usage() sys.exit(0) + elif o in ("-a", "--check-authors-file"): + check_authors_file = True elif o in ("-b", "--skip-block-whitespace"): skip_block_whitespace_check = True elif o in ("-l", "--skip-leading-whitespace"): @@ -1210,6 +1265,7 @@ Subject: %s ovs_checkpatch_print_result() if result: status = EXIT_FAILURE + ovs_checkpatch_print_missing_authors() sys.exit(status) if not args: @@ -1218,6 +1274,7 @@ Subject: %s sys.exit(EXIT_FAILURE) result = ovs_checkpatch_parse(sys.stdin.read(), '-') ovs_checkpatch_print_result() + ovs_checkpatch_print_missing_authors() sys.exit(result) status = 0