Skip to content

Commit 7951fd2

Browse files
authored
Merge branch 'python:3.12' into 3.12
2 parents f2a94b3 + 8fef8f1 commit 7951fd2

File tree

178 files changed

+19108
-18614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+19108
-18614
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ jobs:
1313
run: sudo apt-get install gettext
1414

1515
- name: Validate
16-
run: VERSION=${{ github.event.pull_request.base.ref }} MODE=dummy make all
16+
run: VERSION=${{ github.event.repository.default_branch }} MODE=dummy make all
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: summarize_progress
2+
3+
on:
4+
schedule:
5+
- cron: '30 23 * * 5'
6+
7+
jobs:
8+
ci:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
# Give the default GITHUB_TOKEN write permission to commit and push the
12+
# added or changed files to the repository.
13+
contents: write
14+
steps:
15+
- uses: actions/checkout@v2
16+
17+
- name: Install poetry
18+
uses: abatilo/actions-poetry@v2
19+
20+
- name: Execute Check Process
21+
run: |
22+
chmod +x .scripts/summarize_progress.sh
23+
.scripts/summarize_progress.sh
24+
shell: bash
25+
26+
- uses: stefanzweifel/git-auto-commit-action@v5
27+
with:
28+
commit_message: Weekly Update -- Summarize Progress

.scripts/poetry.lock

+140-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.scripts/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ python = "^3.10"
1010
polib = "1.1.1"
1111
googletrans = "3.1.0a0"
1212
translate-toolkit = "3.8.1"
13-
13+
requests = "2.31.0"
1414

1515
[build-system]
1616
requires = ["poetry-core"]

.scripts/summarize_progress.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
WORK_DIR=.scripts
4+
cd $WORK_DIR
5+
6+
source utils/install_poetry.sh
7+
8+
poetry lock
9+
poetry install
10+
poetry run bash -c "
11+
python summarize_progress/main.py
12+
"

.scripts/summarize_progress/dist/summarize_progress.md

+498
Large diffs are not rendered by default.

.scripts/summarize_progress/main.py

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import re
2+
import polib
3+
import glob
4+
import datetime
5+
import requests
6+
7+
from pathlib import Path
8+
9+
10+
def entry_check(pofile: polib.POFile) -> str:
11+
'''
12+
Check the po file with how many entries are translated or not.
13+
'''
14+
15+
lines_tranlated = len(pofile.translated_entries())
16+
lines_untranlated = len(pofile.untranslated_entries())
17+
18+
if lines_tranlated == 0:
19+
result = "❌"
20+
elif lines_untranlated == 0:
21+
result = "✅"
22+
else:
23+
lines_all = lines_tranlated + lines_untranlated
24+
progress = lines_tranlated / lines_all
25+
progress_percentage = round(progress * 100, 2)
26+
result = f"Ongoing, {progress_percentage} %"
27+
28+
return result
29+
30+
31+
def get_open_issues_count() -> int:
32+
'''
33+
Fetch GitHub API to get the number of OPEN ISSUES.
34+
'''
35+
36+
url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open"
37+
headers = {
38+
"Accept": "application/vnd.github+json",
39+
"X-GitHub-Api-Version": "2022-11-28",
40+
}
41+
r = requests.get(url=url, headers=headers)
42+
result = r.json()
43+
44+
return result["total_count"]
45+
46+
47+
def get_github_issues() -> list:
48+
'''
49+
Fetch GitHub API to collect the infomation of OPEN ISSUES,
50+
including issue title and assignee.
51+
52+
Steps:
53+
1. Fetch GitHub API and get open issue list
54+
2. Filter the issue if it have no assignee
55+
3. Filter the issue if it have no "Translate" in the title
56+
4. Filter the issue if it have no correct filepath in the title
57+
'''
58+
NUMBER_OF_ISSUES = get_open_issues_count()
59+
60+
url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open&per_page={NUMBER_OF_ISSUES}"
61+
headers = {
62+
"Accept": "application/vnd.github+json",
63+
"X-GitHub-Api-Version": "2022-11-28",
64+
}
65+
r = requests.get(url=url, headers=headers)
66+
result = r.json()
67+
68+
result_list = []
69+
for issue in result["items"]:
70+
if issue["assignee"] is None:
71+
continue
72+
73+
title = issue["title"]
74+
if "翻譯" not in title and "translate" not in title.lower():
75+
continue
76+
77+
match = re.search("(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
78+
if not match:
79+
continue
80+
81+
dirname, filename = match.group('dirname', 'filename')
82+
if not filename.endswith('.po'):
83+
filename += '.po'
84+
85+
result_list.append(((dirname, filename), issue["assignee"]["login"]))
86+
87+
return result_list
88+
89+
def format_line_file(filename: str, result: str) -> str:
90+
return f" - {filename.ljust(37, '-')}{result}\r\n"
91+
92+
93+
def format_line_directory(dirname: str) -> str:
94+
return f"- {dirname}/\r\n"
95+
96+
97+
if __name__ == "__main__":
98+
issue_list = get_github_issues()
99+
100+
'''
101+
Search all the po file in the directory,
102+
and record the translation progress of each files.
103+
'''
104+
BASE_DIR = Path("../")
105+
summary = {}
106+
for filepath in glob.glob(str(BASE_DIR / "**/*.po"), recursive=True):
107+
path = Path(filepath)
108+
filename = path.name
109+
dirname = path.parent.name if path.parent.name != BASE_DIR.name else '/'
110+
po = polib.pofile(filepath)
111+
summary.setdefault(dirname, {})[filename] = entry_check(po)
112+
113+
'''
114+
Unpack the open issue list, and add assignee after the progress
115+
'''
116+
for (category, filename), assignee in issue_list:
117+
try:
118+
summary[category][filename] += f", 💻 {assignee}"
119+
except KeyError:
120+
pass
121+
122+
'''
123+
Format the lines that will write into the markdown file,
124+
also sort the directory name and file name.
125+
'''
126+
writeliner = []
127+
summary_sorted = dict(sorted(summary.items()))
128+
for dirname, filedict in summary_sorted.items():
129+
writeliner.append(format_line_directory(dirname))
130+
filedict_sorted = dict(sorted(filedict.items()))
131+
for filename, result in filedict_sorted.items():
132+
writeliner.append(format_line_file(filename, result))
133+
134+
with open(
135+
f"summarize_progress/dist/summarize_progress.md",
136+
"w",
137+
) as file:
138+
file.writelines(writeliner)

Makefile

+1-4
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ endif
105105
mkdir -p "$$(dirname "$$PO")";\
106106
if [ -f "$$PO" ];\
107107
then\
108-
case "$$POT" in\
109-
*whatsnew*) msgmerge --lang=$(LANGUAGE) --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\
110-
*) msgmerge --lang=$(LANGUAGE) --backup=off --force-po -U "$$PO" "$$POT" ;;\
111-
esac\
108+
msgmerge --lang=$(LANGUAGE) --backup=off --force-po -U "$$PO" "$$POT";\
112109
else\
113110
msgcat --lang=$(LANGUAGE) -o "$$PO" "$$POT";\
114111
fi\

bugs.po

+5-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ msgid ""
1313
msgstr ""
1414
"Project-Id-Version: Python 3.12\n"
1515
"Report-Msgid-Bugs-To: \n"
16-
"POT-Creation-Date: 2023-02-27 00:17+0000\n"
16+
"POT-Creation-Date: 2023-11-05 09:50+0000\n"
1717
"PO-Revision-Date: 2022-08-31 12:34+0800\n"
1818
"Last-Translator: Steven Hsu <hsuhaochun@gmail.com>\n"
1919
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
@@ -117,9 +117,10 @@ msgstr "給有意成為 Python 說明文件貢獻者的綜合指南。"
117117

118118
#: ../../bugs.rst:41
119119
msgid ""
120-
"`Documentation Translations <https://devguide.python.org/documenting/"
121-
"#translating>`_"
122-
msgstr "`說明文件翻譯 <https://devguide.python.org/documenting/#translating>`_"
120+
"`Documentation Translations <https://devguide.python.org/documentation/"
121+
"translating/>`_"
122+
msgstr ""
123+
"`說明文件翻譯 <https://devguide.python.org/documentation/translating/>`_"
123124

124125
#: ../../bugs.rst:42
125126
msgid ""

0 commit comments

Comments
 (0)