8
8
import pathlib
9
9
import subprocess
10
10
import tempfile
11
+ import unicodedata
11
12
from typing import Iterator , List , Optional , Set
12
13
13
14
from nox .sessions import Session
@@ -45,6 +46,34 @@ def modified_files_in_git(*args: str) -> int:
45
46
).returncode
46
47
47
48
49
+ def strip_rtl_ltr_overrides (a : str ) -> str :
50
+ """Strip RIGHT-TO-LEFT OVERRIDE and LEFT-TO-RIGHT OVERRIDE characters
51
+ from author names.
52
+ Reorder the characters in between them to preserve the perception.
53
+ See https://github.com/pypa/pip/issues/12467 for more info."""
54
+ rtl = "\N{RIGHT-TO-LEFT OVERRIDE} "
55
+ ltr = "\N{LEFT-TO-RIGHT OVERRIDE} "
56
+
57
+ # If there are no overrides to RIGHT-TO-LEFT,
58
+ # only strip useless LEFT-TO-RIGHT overrides.
59
+ # This returns the original for most of the authors.
60
+ # It also serves as a termination condition for recursive calls.
61
+ if rtl not in a :
62
+ return a .replace (ltr , "" )
63
+
64
+ prefix = a [: a .index (rtl )].replace (ltr , "" )
65
+ rest = a [: a .index (rtl ) : - 1 ]
66
+ if ltr not in rest :
67
+ rest = rest .replace (rtl , "" )
68
+ else :
69
+ rest = a [a .index (ltr ) - 1 : a .index (rtl ) : - 1 ].replace (rtl , "" )
70
+ rest += a [a .index (ltr ) + 1 :]
71
+ combined = prefix + strip_rtl_ltr_overrides (rest )
72
+ assert rtl not in combined , f"RIGHT-TO-LEFT OVERRIDE in { combined !r} "
73
+ assert ltr not in combined , f"LEFT-TO-RIGHT OVERRIDE in { combined !r} "
74
+ return combined
75
+
76
+
48
77
def get_author_list () -> List [str ]:
49
78
"""Get the list of authors from Git commits."""
50
79
# subprocess because session.run doesn't give us stdout
@@ -60,6 +89,8 @@ def get_author_list() -> List[str]:
60
89
seen_authors : Set [str ] = set ()
61
90
for author in result .stdout .splitlines ():
62
91
author = author .strip ()
92
+ author = strip_rtl_ltr_overrides (author )
93
+ author = unicodedata .normalize ("NFC" , author )
63
94
if author .lower () not in seen_authors :
64
95
seen_authors .add (author .lower ())
65
96
authors .append (author )
0 commit comments