From patchwork Mon Sep 30 13:19:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 1991000 X-Patchwork-Delegate: aconole@redhat.com 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=gYTtVb4N; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 4XHMBZ2g6vz1xsc for ; Mon, 30 Sep 2024 23:20:22 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 228B140232; Mon, 30 Sep 2024 13:20:20 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id zXGYQ_7pE91b; Mon, 30 Sep 2024 13:20:18 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.9.56; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A0D6B400D1 Authentication-Results: smtp4.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=gYTtVb4N Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id A0D6B400D1; Mon, 30 Sep 2024 13:20:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C962FC002B; Mon, 30 Sep 2024 13:20:17 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 00F39C002A for ; Mon, 30 Sep 2024 13:20:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id E995840226 for ; Mon, 30 Sep 2024 13:20:15 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id OuU3R8BqerQo for ; Mon, 30 Sep 2024 13:20:15 +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 smtp4.osuosl.org A67EC400D1 Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A67EC400D1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id A67EC400D1 for ; Mon, 30 Sep 2024 13:20:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727702413; 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=Zg6YCYPqEM5MaaTNysCHzXoLuocBSZ5o/1Ez41ql5IQ=; b=gYTtVb4N9tvZ2i4/WoIe/Qw52iUqyvvatzlWe/jo/m4EdAocJQpe4AemtP0D58CJYr9ZAm dILBwXSZIHER+xCsxOuFgM7e9B98Di9Qj6jJANT2HeDCvl8l6z2iGzL4uI6ICY843+5Q8j 2ZOaAo0ewvsP/tL6JLR0vB8RSVjEK+E= Received: from mx-prod-mc-01.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-220-PcN7C-SMPwa07FHXyLA4rw-1; Mon, 30 Sep 2024 09:20:11 -0400 X-MC-Unique: PcN7C-SMPwa07FHXyLA4rw-1 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (unknown [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9758219792DE; Mon, 30 Sep 2024 13:20:10 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.194.95]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7C7C41955DCB; Mon, 30 Sep 2024 13:20:09 +0000 (UTC) From: Eelco Chaudron To: dev@openvswitch.org Date: Mon, 30 Sep 2024 15:19:09 +0200 Message-ID: <4b17ae74e848225860b556c705607cb115e258e0.1727702349.git.echaudro@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH v4] 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. v4: - Added a test case. --- tests/checkpatch.at | 21 +++++++++++++ utilities/checkpatch.py | 68 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/tests/checkpatch.at b/tests/checkpatch.at index 34971c514..fa179c707 100755 --- a/tests/checkpatch.at +++ b/tests/checkpatch.at @@ -634,3 +634,24 @@ try_checkpatch \ "--skip-committer-signoff" AT_CLEANUP + +AT_SETUP([checkpatch - AUTHORS.rst existence]) + +try_checkpatch \ + "Author: A + Commit: A + Subject: netdev: Subject. + + Signed-off-by: A " \ + "" + +try_checkpatch \ + "Author: A + Commit: A + Subject: netdev: Subject. + + Signed-off-by: A " \ + "WARNING: Author 'A ' is not in the AUTHORS.rst file!" \ + "-a" + +AT_CLEANUP diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 742a0bc47..73c20f804 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,19 @@ 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)) + return True + + return False + + def ovs_checkpatch_file(filename): try: mail = email.message_from_file(open(filename, 'r', encoding='utf8')) @@ -1116,6 +1170,8 @@ def ovs_checkpatch_file(filename): result = True ovs_checkpatch_print_result() + if ovs_checkpatch_print_missing_authors(): + result = True return result @@ -1138,9 +1194,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 +1214,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"): @@ -1207,9 +1266,10 @@ Subject: %s if not quiet: print('== Checking %s ("%s") ==' % (revision[0:12], name)) result = ovs_checkpatch_parse(patch, revision) - ovs_checkpatch_print_result() if result: status = EXIT_FAILURE + if ovs_checkpatch_print_missing_authors(): + status = EXIT_FAILURE sys.exit(status) if not args: @@ -1218,6 +1278,8 @@ Subject: %s sys.exit(EXIT_FAILURE) result = ovs_checkpatch_parse(sys.stdin.read(), '-') ovs_checkpatch_print_result() + if ovs_checkpatch_print_missing_authors(): + result = EXIT_FAILURE sys.exit(result) status = 0