public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Martin Liska <marxin@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-6436] Check sorting of MAINTAINERS.
Date: Tue, 11 Jan 2022 13:13:15 +0000 (GMT)	[thread overview]
Message-ID: <20220111131315.5C4C53858D39@sourceware.org> (raw)

https://gcc.gnu.org/g:11b26b8d2e0521f1d44dfb460b51ea8164af7dce

commit r12-6436-g11b26b8d2e0521f1d44dfb460b51ea8164af7dce
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Jan 10 16:49:31 2022 +0100

    Check sorting of MAINTAINERS.
    
    contrib/ChangeLog:
    
            * check-MAINTAINERS.py: New file.

Diff:
---
 contrib/check-MAINTAINERS.py | 113 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 113 insertions(+)

diff --git a/contrib/check-MAINTAINERS.py b/contrib/check-MAINTAINERS.py
new file mode 100755
index 00000000000..ca7bb291282
--- /dev/null
+++ b/contrib/check-MAINTAINERS.py
@@ -0,0 +1,113 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2022 Free Software Foundation, Inc.
+#
+# This file is part of GCC.
+#
+# GCC is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GCC is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING.  If not, write to
+# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+# Check that names in the file are sorted
+# alphabetically by surname.
+
+import locale
+import sys
+from difflib import ndiff
+from itertools import dropwhile, takewhile
+
+import unidecode
+
+locale.setlocale(locale.LC_ALL, 'en_US.utf8')
+
+exit_code = 0
+
+if len(sys.argv) != 2:
+    print('Usage: ./check-MAINTAINERS.py path-to/MAINTAINERS')
+    sys.exit(1)
+
+
+def sort_by_surname(line):
+    name = line.split('\t')[0]
+    parts = name.split()
+    surname = parts[-1]
+
+    # Special-case some names
+    if name == 'Stefan Schulze Frielinghaus':
+        surname = parts[1]
+    elif name == 'Kris Van Hees':
+        surname = parts[1]
+    elif surname == "d'Humieres":
+        surname = 'Humieres'
+
+    # Remove accents
+    return (unidecode.unidecode(surname), line)
+
+
+def has_tab(line):
+    return '\t' in line
+
+
+def is_empty(line):
+    return line
+
+
+def check_group(name, lines):
+    global exit_code
+
+    for line in lines:
+        if line.startswith(' '):
+            print(f'Line should not start with space: "{line}"')
+            exit_code = 2
+
+    lines = [line + '\n' for line in lines]
+    sorted_lines = sorted(lines, key=sort_by_surname)
+    if lines != sorted_lines:
+        exit_code = 1
+        diff = ndiff(lines, sorted_lines)
+        print(f'Wrong order for {name}:\n')
+        print(''.join(diff))
+    else:
+        print(f'{name} are fine!')
+
+
+lines = open('MAINTAINERS').read().splitlines()
+
+needle = 'Global Reviewers'
+lines = list(dropwhile(lambda x: x.strip() != needle, lines))
+lines = lines[2:]
+
+chunk = list(takewhile(is_empty, lines))
+check_group(needle, chunk)
+
+needle = 'Write After Approval'
+lines = list(dropwhile(lambda x: needle not in x, lines))
+lines = lines[2:]
+
+chunk = list(takewhile(is_empty, lines))
+check_group(needle, chunk)
+
+needle = 'Bug database only accounts'
+lines = list(dropwhile(lambda x: needle not in x, lines))
+lines = lines[2:]
+
+chunk = list(takewhile(is_empty, lines))
+check_group(needle, chunk)
+
+needle = 'Contributing under the DCO'
+lines = list(dropwhile(lambda x: needle not in x, lines))[1:]
+lines = list(dropwhile(lambda x: not has_tab(x), lines))
+check_group(needle, lines)
+
+sys.exit(exit_code)


                 reply	other threads:[~2022-01-11 13:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220111131315.5C4C53858D39@sourceware.org \
    --to=marxin@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).