Skip to content

Commit 7673a51

Browse files
authored
Merge pull request #12517 from hroncok/stripoverrides
2 parents 5b9306f + 239c1d4 commit 7673a51

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

AUTHORS.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ Mark Williams
445445
Markus Hametner
446446
Martey Dodoo
447447
Martin Fischer
448-
Martin Häcker
448+
Martin Häcker
449449
Martin Pavlasek
450450
Masaki
451451
Masklinn
@@ -495,7 +495,7 @@ Miro Hrončok
495495
Monica Baluna
496496
montefra
497497
Monty Taylor
498-
Muha Ajjan
498+
Muha Ajjan
499499
Nadav Wexler
500500
Nahuel Ambrosini
501501
Nate Coraor
@@ -757,4 +757,3 @@ Zvezdan Petkovic
757757
Łukasz Langa
758758
Роман Донченко
759759
Семён Марьясин
760-
‮rekcäH nitraM‮

tools/release/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pathlib
99
import subprocess
1010
import tempfile
11+
import unicodedata
1112
from typing import Iterator, List, Optional, Set
1213

1314
from nox.sessions import Session
@@ -45,6 +46,34 @@ def modified_files_in_git(*args: str) -> int:
4546
).returncode
4647

4748

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+
4877
def get_author_list() -> List[str]:
4978
"""Get the list of authors from Git commits."""
5079
# subprocess because session.run doesn't give us stdout
@@ -60,6 +89,8 @@ def get_author_list() -> List[str]:
6089
seen_authors: Set[str] = set()
6190
for author in result.stdout.splitlines():
6291
author = author.strip()
92+
author = strip_rtl_ltr_overrides(author)
93+
author = unicodedata.normalize("NFC", author)
6394
if author.lower() not in seen_authors:
6495
seen_authors.add(author.lower())
6596
authors.append(author)

0 commit comments

Comments
 (0)