On 30 Sep 2024, at 14:39, Eelco Chaudron wrote:
> 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 <[email protected]>
> ---
> 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.
> ---
Ignore this version I forgot to add a test case, and refresh the flake8 changes
:(
//Eelco
> 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
> --
> 2.46.0
>
> _______________________________________________
> dev mailing list
> [email protected]
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev