Skip to content

Commit c6caa61

Browse files
committed
Run black on scripts
1 parent 17cd2ec commit c6caa61

6 files changed

Lines changed: 206 additions & 73 deletions

File tree

scripts/check_markup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ def check_file(path: Path) -> int:
7777

7878
if findings:
7979
problems += 1
80-
loc = f" ({entry.occurrences[0][0]}:{entry.occurrences[0][1]})" if entry.occurrences else ""
80+
loc = (
81+
f" ({entry.occurrences[0][0]}:{entry.occurrences[0][1]})"
82+
if entry.occurrences
83+
else ""
84+
)
8185
tag = " [fuzzy]" if entry.fuzzy else ""
8286
print(f"{path}{loc}{tag}: {'; '.join(findings)}")
8387
print(f" msgid : {entry.msgid[:100]}")

scripts/generate_status_table.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828

2929
def file_stats(path: Path):
3030
po = polib.pofile(str(path))
31-
return len(po.translated_entries()), len(po.fuzzy_entries()), len(po.untranslated_entries())
31+
return (
32+
len(po.translated_entries()),
33+
len(po.fuzzy_entries()),
34+
len(po.untranslated_entries()),
35+
)
3236

3337

3438
def build_table() -> str:
@@ -58,8 +62,11 @@ def build_table() -> str:
5862

5963
def main():
6064
parser = argparse.ArgumentParser(description=__doc__)
61-
parser.add_argument("--file", default="STATUS.md",
62-
help="Markdown file containing the marker block to update")
65+
parser.add_argument(
66+
"--file",
67+
default="STATUS.md",
68+
help="Markdown file containing the marker block to update",
69+
)
6370
args = parser.parse_args()
6471

6572
target = REPO_ROOT / args.file

scripts/team_stats.py

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
3838
REPO_ROOT = Path(__file__).resolve().parent.parent
3939

4040
BOT_NAME_RE = re.compile(
41-
r'github[^\w]*actions|\[bot\]|not committed yet', re.IGNORECASE)
41+
r"github[^\w]*actions|\[bot\]|not committed yet", re.IGNORECASE
42+
)
4243
BOT_EMAIL_RE = re.compile(
43-
r'github-actions|transifex|\[bot\]|@users\.noreply\.github\.com',
44+
r"github-actions|transifex|\[bot\]|@users\.noreply\.github\.com",
4445
re.IGNORECASE,
4546
)
4647
MECHANICAL_SUBJECT_RE = re.compile(
47-
r'^(?:sync\s+translations\s+with\s+cpython\b'
48-
r'|update\s+\.po\s+files(?:\s*\(\d+\))?\s*$'
49-
r'|update\s+farsi\s+translations\s+from\s+transifex\b)',
48+
r"^(?:sync\s+translations\s+with\s+cpython\b"
49+
r"|update\s+\.po\s+files(?:\s*\(\d+\))?\s*$"
50+
r"|update\s+farsi\s+translations\s+from\s+transifex\b)",
5051
re.IGNORECASE,
5152
)
5253

@@ -70,15 +71,16 @@
7071
SKIP_DIRS = {".git", ".cpython-src", ".venv", "__pycache__", "venv"}
7172

7273
TEAMMD_ROW_RE = re.compile(
73-
r'^\|\s*(?P<user>[^|]+?)\s*\|\s*(?P<role>[^|]+?)\s*\|\s*'
74-
r'(?P<t>\d+(?:\s*\([^)]*\))?)\s*\|$'
74+
r"^\|\s*(?P<user>[^|]+?)\s*\|\s*(?P<role>[^|]+?)\s*\|\s*"
75+
r"(?P<t>\d+(?:\s*\([^)]*\))?)\s*\|$"
7576
)
7677

7778

7879
# ---------------------------------------------------------------------------
7980
# Privacy helper
8081
# ---------------------------------------------------------------------------
8182

83+
8284
def redact_email(email: str) -> str:
8385
"""Return a partially redacted email for warning messages.
8486
@@ -109,6 +111,7 @@ def _blur(s: str) -> str:
109111
# Git helpers
110112
# ---------------------------------------------------------------------------
111113

114+
112115
def _is_mechanical(subject: str) -> bool:
113116
return bool(MECHANICAL_SUBJECT_RE.search(subject))
114117

@@ -124,9 +127,18 @@ def git_blame_porcelain(path: Path) -> dict[str, dict]:
124127
``lines`` (a set of 1-based line numbers blamed to that commit).
125128
"""
126129
result = subprocess.run(
127-
["git", "-C", str(REPO_ROOT), "blame", "--porcelain",
128-
"--", str(path.resolve().relative_to(REPO_ROOT))],
129-
capture_output=True, text=True, check=False,
130+
[
131+
"git",
132+
"-C",
133+
str(REPO_ROOT),
134+
"blame",
135+
"--porcelain",
136+
"--",
137+
str(path.resolve().relative_to(REPO_ROOT)),
138+
],
139+
capture_output=True,
140+
text=True,
141+
check=False,
130142
)
131143
if result.returncode != 0:
132144
return {}
@@ -137,20 +149,26 @@ def git_blame_porcelain(path: Path) -> dict[str, dict]:
137149
for raw_line in result.stdout.splitlines():
138150
# Commit header: "<40-char-hash> <orig-line> <result-line> [<num-lines>]"
139151
parts = raw_line.split()
140-
if len(parts) >= 3 and len(parts[0]) == 40 and parts[0].isalnum() and parts[1].isdigit() and parts[2].isdigit():
152+
if (
153+
len(parts) >= 3
154+
and len(parts[0]) == 40
155+
and parts[0].isalnum()
156+
and parts[1].isdigit()
157+
and parts[2].isdigit()
158+
):
141159
h = parts[0]
142160
result_line = int(parts[2])
143161
current_hash = h
144162
if h not in commits:
145163
commits[h] = {"name": "", "email": "", "subject": "", "lines": set()}
146164
commits[h]["lines"].add(result_line)
147165
elif raw_line.startswith("author ") and current_hash:
148-
commits[current_hash]["name"] = raw_line[len("author "):].strip()
166+
commits[current_hash]["name"] = raw_line[len("author ") :].strip()
149167
elif raw_line.startswith("author-mail ") and current_hash:
150-
email = raw_line[len("author-mail "):].strip().strip("<>")
168+
email = raw_line[len("author-mail ") :].strip().strip("<>")
151169
commits[current_hash]["email"] = email.lower()
152170
elif raw_line.startswith("summary ") and current_hash:
153-
commits[current_hash]["subject"] = raw_line[len("summary "):]
171+
commits[current_hash]["subject"] = raw_line[len("summary ") :]
154172

155173
return commits
156174

@@ -212,6 +230,7 @@ def real_author_for_lines(
212230
# .po file walking
213231
# ---------------------------------------------------------------------------
214232

233+
215234
def collect_files(paths: list[str]) -> list[Path]:
216235
files = []
217236
for arg in paths:
@@ -314,6 +333,7 @@ def teammd_totals() -> dict[str, int]:
314333
# Output
315334
# ---------------------------------------------------------------------------
316335

336+
317337
def print_report(counts: dict[str, int]) -> None:
318338
total = sum(counts.values())
319339
print(f"Total non-fuzzy translated entries attributed: {total}\n")
@@ -371,17 +391,21 @@ def update_teammd(counts: dict[str, int]) -> None:
371391
# Entry point
372392
# ---------------------------------------------------------------------------
373393

394+
374395
def main() -> None:
375396
parser = argparse.ArgumentParser(
376397
description=__doc__,
377398
formatter_class=argparse.RawDescriptionHelpFormatter,
378399
)
379400
parser.add_argument(
380-
"paths", nargs="*", default=["."],
401+
"paths",
402+
nargs="*",
403+
default=["."],
381404
help="Files or directories to scan (default: whole repo)",
382405
)
383406
parser.add_argument(
384-
"--update-teammd", action="store_true",
407+
"--update-teammd",
408+
action="store_true",
385409
help="rewrite TEAM.md from the computed counts",
386410
)
387411
args = parser.parse_args()

scripts/translation_status.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424

2525
def file_stats(path: Path):
2626
po = polib.pofile(str(path))
27-
return len(po.translated_entries()), len(po.fuzzy_entries()), len(po.untranslated_entries())
27+
return (
28+
len(po.translated_entries()),
29+
len(po.fuzzy_entries()),
30+
len(po.untranslated_entries()),
31+
)
2832

2933

3034
def collect_files(paths):
@@ -45,12 +49,23 @@ def main():
4549
parser = argparse.ArgumentParser(
4650
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
4751
)
48-
parser.add_argument("paths", nargs="*", default=["."],
49-
help="Files or directories to scan (default: whole repo)")
50-
parser.add_argument("--sort", choices=["percent", "untranslated", "name"], default="percent",
51-
help="Sort order (default: percent, least-translated first)")
52-
parser.add_argument("--only-incomplete", action="store_true",
53-
help="Hide files that are already fully translated")
52+
parser.add_argument(
53+
"paths",
54+
nargs="*",
55+
default=["."],
56+
help="Files or directories to scan (default: whole repo)",
57+
)
58+
parser.add_argument(
59+
"--sort",
60+
choices=["percent", "untranslated", "name"],
61+
default="percent",
62+
help="Sort order (default: percent, least-translated first)",
63+
)
64+
parser.add_argument(
65+
"--only-incomplete",
66+
action="store_true",
67+
help="Hide files that are already fully translated",
68+
)
5469
parser.add_argument("--format", choices=["text", "markdown", "csv"], default="text")
5570
args = parser.parse_args()
5671

@@ -94,7 +109,9 @@ def main():
94109
print("|---|---:|---:|---:|---:|")
95110
for path, t, fz, u, total, percent in rows:
96111
print(f"| `{path}` | {t} | {fz} | {u} | {percent:.1f}% |")
97-
print(f"| **TOTAL** | **{total_t}** | **{total_fz}** | **{total_u}** | **{total_percent:.1f}%** |")
112+
print(
113+
f"| **TOTAL** | **{total_t}** | **{total_fz}** | **{total_u}** | **{total_percent:.1f}%** |"
114+
)
98115
return
99116

100117
name_width = max((len(r[0]) for r in rows), default=4)
@@ -104,9 +121,13 @@ def main():
104121
for path, t, fz, u, total, percent in rows:
105122
print(f"{path:<{name_width}} {t:>10} {fz:>6} {u:>12} {percent:>6.1f}%")
106123
print("-" * len(header))
107-
print(f"{'TOTAL':<{name_width}} {total_t:>10} {total_fz:>6} {total_u:>12} {total_percent:>6.1f}%")
108-
print(f"\n{len(rows)} file(s) shown. "
109-
f"{sum(1 for r in rows if r[5] < 100)} file(s) not fully translated.")
124+
print(
125+
f"{'TOTAL':<{name_width}} {total_t:>10} {total_fz:>6} {total_u:>12} {total_percent:>6.1f}%"
126+
)
127+
print(
128+
f"\n{len(rows)} file(s) shown. "
129+
f"{sum(1 for r in rows if r[5] < 100)} file(s) not fully translated."
130+
)
110131

111132

112133
if __name__ == "__main__":

0 commit comments

Comments
 (0)