Skip to content

Commit d3a7873

Browse files
committed
Update scripts
1 parent 824e943 commit d3a7873

File tree

4 files changed

+51
-46
lines changed

4 files changed

+51
-46
lines changed

merge.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ def update_makefile(cpython_repo: Path) -> None:
8080
used to generate the `po` files.
8181
"""
8282
makefile = Path("Makefile").read_text(encoding="UTF-8")
83-
head = run(
84-
"git", "-C", cpython_repo, "rev-parse", "HEAD", stdout=PIPE
85-
).stdout.strip()
83+
head = run("git", "-C", cpython_repo, "rev-parse", "HEAD", stdout=PIPE).stdout.strip()
8684
makefile = re.sub(
8785
"^CPYTHON_CURRENT_COMMIT :=.*$",
8886
f"CPYTHON_CURRENT_COMMIT := {head}",
@@ -101,14 +99,8 @@ def main():
10199
cwd=args.cpython_repo / "Doc",
102100
)
103101
pot_path = args.cpython_repo / "pot"
104-
upstream = {
105-
file.relative_to(pot_path).with_suffix(".po")
106-
for file in pot_path.glob("**/*.pot")
107-
}
108-
downstream = {
109-
Path(po)
110-
for po in run("git", "ls-files", "*.po", stdout=PIPE).stdout.splitlines()
111-
}
102+
upstream = {file.relative_to(pot_path).with_suffix(".po") for file in pot_path.glob("**/*.pot")}
103+
downstream = {Path(po) for po in run("git", "ls-files", "*.po", stdout=PIPE).stdout.splitlines()}
112104
copy_new_files(upstream - downstream, pot_path=pot_path)
113105
update_known_files(upstream & downstream, pot_path=pot_path)
114106
remove_old_files(downstream - upstream)

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
poutils
22
tqdm
3-
sphinx-lint
43
pre-commit
54
polib

scripts/format_check.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88

99

1010
parser = argparse.ArgumentParser()
11-
parser.add_argument(
12-
"subject", nargs="?", default=None, help="Subject to check (file or directory)"
13-
)
11+
parser.add_argument("subject", nargs="?", default=None, help="Subject to check (file or directory)")
1412
parser.add_argument("-t", "--threshold", type=int, default=85)
1513
args = parser.parse_args()
1614

@@ -30,11 +28,7 @@
3028

3129
elif os.path.isfile(args.subject):
3230
is_file = True
33-
subject = (
34-
args.subject
35-
if os.path.isabs(args.subject)
36-
else os.path.join(subject, args.subject)
37-
)
31+
subject = args.subject if os.path.isabs(args.subject) else os.path.join(subject, args.subject)
3832

3933
else:
4034
print("Invalid subject, showing all files.")
@@ -62,9 +56,7 @@ def main(subject):
6256
wordsid = [word for word in entry.msgid.split() if has_delimiters(word)]
6357

6458
if has_delimiters(entry.msgstr):
65-
wordsstr = [
66-
word for word in entry.msgstr.split() if has_delimiters(word)
67-
]
59+
wordsstr = [word for word in entry.msgstr.split() if has_delimiters(word)]
6860

6961
if len(wordsid) != len(wordsstr):
7062
key = pofilename

scripts/progress.py

+45-23
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66

77

88
parser = argparse.ArgumentParser()
9-
parser.add_argument(
10-
"subject", nargs="?", default=None, help="Subject to check (file or directory)"
11-
)
9+
parser.add_argument("subject", nargs="?", default=None, help="Subject to check (file or directory)")
1210
parser.add_argument("-c", "--completed", action="store_true")
1311
parser.add_argument("-t", "--threshold", type=int, default=90)
1412
args = parser.parse_args()
@@ -28,38 +26,62 @@
2826

2927
elif os.path.isfile(args.subject):
3028
is_file = True
31-
args.subject = (
32-
args.subject
33-
if os.path.isabs(args.subject)
34-
else os.path.join(PO_DIR, args.subject)
35-
)
29+
args.org_subject = args.subject
30+
args.subject = args.subject if os.path.isabs(args.subject) else os.path.join(PO_DIR, args.subject)
3631

3732
else:
3833
print("Invalid subject, showing all files.")
3934

4035

36+
def po_stats(pofilename):
37+
po = polib.pofile(pofilename)
38+
translated = len(po.translated_entries())
39+
total = len(po) + translated
40+
return (po.percent_translated(), translated, total)
41+
42+
4143
def main():
4244
files = []
45+
translated = []
46+
total = []
4347
if is_file:
4448
po = polib.pofile(args.subject)
45-
return [[args.subject.replace(PO_DIR, ""), po.percent_translated()]]
49+
return os.path.relpath(args.org_subject), po.percent_translated()
4650

4751
for pofilename in glob.glob(f"{PO_DIR}**/*.po"):
48-
po = polib.pofile(pofilename)
49-
files.append((pofilename.replace(PO_DIR, ""), po.percent_translated()))
52+
stats = po_stats(pofilename)
53+
translated.append(stats[1])
54+
total.append(stats[2])
55+
files.append((os.path.relpath(pofilename).replace("\\", "/"), stats[0]))
5056
for pofilename in glob.glob(f"{PO_DIR}**/**/*.po"):
51-
po = polib.pofile(pofilename)
52-
files.append((pofilename.replace(PO_DIR, ""), po.percent_translated()))
53-
return files
57+
stats = po_stats(pofilename)
58+
translated.append(stats[1])
59+
total.append(stats[2])
60+
files.append((os.path.relpath(pofilename).replace("\\", "/"), stats[0]))
61+
return files, round(sum(translated) / sum(total) * 100, 1)
5462

5563

5664
if __name__ == "__main__":
57-
results = [f"{file[0]}: {file[1]}%" for file in main()]
58-
59-
for result in results:
60-
if args.completed and int(result.split(" ")[1].replace("%", "")) > min(
61-
args.threshold, 100
62-
):
63-
print(result)
64-
elif not args.completed:
65-
print(result)
65+
files, weighted_progress = main()
66+
if not args.subject:
67+
print("No subject provided, showing general progress")
68+
print(f"{len([file for file in files if file[1] > min(args.threshold, 100)])} / {len(files)} files completed")
69+
print(f"Weighted progress: {weighted_progress}%\n")
70+
71+
if args.completed:
72+
print("Completed files:")
73+
completed_files = [file for file in files if file[1] > min(args.threshold, 100)]
74+
for file, percentage in completed_files:
75+
print(f"{file}: {percentage}%")
76+
elif is_file:
77+
print(f"{files}: {weighted_progress}%")
78+
79+
else:
80+
print(f"{len([file for file in files if file[1] > min(args.threshold, 100)])} / {len(files)} files completed")
81+
print(f"Weighted progress: {weighted_progress}%\n")
82+
83+
if args.completed:
84+
print("Completed files:")
85+
completed_files = [file for file in files if file[1] > min(args.threshold, 100)]
86+
for file, percentage in completed_files:
87+
print(f"{file}: {percentage}%")

0 commit comments

Comments
 (0)