Skip to content

Commit 3c56678

Browse files
authored
Merge branch '3.12' into library/hashlib
2 parents 499e6cf + 68c024f commit 3c56678

File tree

367 files changed

+32356
-28710
lines changed

Some content is hidden

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

367 files changed

+32356
-28710
lines changed

.github/workflows/summarize_progress.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66

77
jobs:
88
ci:
9+
if: github.repository == 'python/python-docs-zh-tw'
910
runs-on: ubuntu-latest
1011
permissions:
1112
# Give the default GITHUB_TOKEN write permission to commit and push the
@@ -32,7 +33,7 @@ jobs:
3233

3334
- name: Copy content
3435
run: |
35-
cp .scripts/summarize_progress/dist/summarize_progress.md markdown/各檔案翻譯進度清單.md
36+
cp .scripts/summarize_progress/result.md markdown/各檔案翻譯進度清單.md
3637
shell: bash
3738

3839
- name: Commit wiki code

.scripts/poetry.lock

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

.scripts/summarize_progress/dist/summarize_progress.md

-498
This file was deleted.

.scripts/summarize_progress/main.py

+41-18
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
import polib
33
import glob
4-
import datetime
54
import requests
65

76
from pathlib import Path
@@ -23,7 +22,7 @@ def entry_check(pofile: polib.POFile) -> str:
2322
lines_all = lines_tranlated + lines_untranlated
2423
progress = lines_tranlated / lines_all
2524
progress_percentage = round(progress * 100, 2)
26-
result = f"Ongoing, {progress_percentage} %"
25+
result = f"{progress_percentage} %"
2726

2827
return result
2928

@@ -51,9 +50,11 @@ def get_github_issues() -> list:
5150
5251
Steps:
5352
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
53+
2. Filter the issue if it have no "Translate" in the title
54+
3. Filter the issue if it have no correct filepath in the title
55+
56+
Expected Output:
57+
[ ((dirname, filename), assignee_id, issue_url), ... ]
5758
'''
5859
NUMBER_OF_ISSUES = get_open_issues_count()
5960

@@ -67,31 +68,41 @@ def get_github_issues() -> list:
6768

6869
result_list = []
6970
for issue in result["items"]:
70-
if issue["assignee"] is None:
71-
continue
71+
assignee = issue["assignee"]["login"] if issue["assignee"] else ""
7272

7373
title = issue["title"]
7474
if "翻譯" not in title and "translate" not in title.lower():
7575
continue
7676

77-
match = re.search("(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
77+
match = re.search(
78+
"(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
7879
if not match:
7980
continue
8081

8182
dirname, filename = match.group('dirname', 'filename')
8283
if not filename.endswith('.po'):
8384
filename += '.po'
8485

85-
result_list.append(((dirname, filename), issue["assignee"]["login"]))
86+
result_list.append(((dirname, filename), assignee, issue["html_url"]))
8687

8788
return result_list
8889

89-
def format_line_file(filename: str, result: str) -> str:
90-
return f" - {filename.ljust(37, '-')}{result}\r\n"
90+
91+
def format_line_table_header() -> list:
92+
return [f"|Filename|Progress|Issue|Assignee|\r\n",
93+
f"|-------:|:-------|:----|:-------|\r\n"]
94+
95+
96+
def format_issue_link(url: str) -> str:
97+
return f"[{url.split('/')[-1]}]({url})" if len(url) > 0 else ''
98+
99+
100+
def format_line_file(filename: str, data: dict) -> str:
101+
return f"|`{filename}`|{data['progress']}|{format_issue_link(data['issue'])}|{data['assignee']}|\r\n"
91102

92103

93104
def format_line_directory(dirname: str) -> str:
94-
return f"- {dirname}/\r\n"
105+
return f"## {dirname}\r\n"
95106

96107

97108
if __name__ == "__main__":
@@ -108,17 +119,27 @@ def format_line_directory(dirname: str) -> str:
108119
filename = path.name
109120
dirname = path.parent.name if path.parent.name != BASE_DIR.name else '/'
110121
po = polib.pofile(filepath)
111-
summary.setdefault(dirname, {})[filename] = entry_check(po)
122+
123+
summary.setdefault(dirname, {})[filename] = {
124+
'progress': entry_check(po),
125+
'issue': '',
126+
'assignee': '',
127+
}
112128

113129
'''
114130
Unpack the open issue list, and add assignee after the progress
115131
'''
116-
for (category, filename), assignee in issue_list:
132+
for (category, filename), assignee, issue_url in issue_list:
117133
try:
118-
summary[category][filename] += f", 💻 {assignee}"
134+
summary[category][filename]['issue'] = issue_url
135+
summary[category][filename]['assignee'] = assignee
119136
except KeyError:
120137
pass
121138

139+
'''
140+
Adding Space for Formatting Markdown Link
141+
'''
142+
122143
'''
123144
Format the lines that will write into the markdown file,
124145
also sort the directory name and file name.
@@ -127,12 +148,14 @@ def format_line_directory(dirname: str) -> str:
127148
summary_sorted = dict(sorted(summary.items()))
128149
for dirname, filedict in summary_sorted.items():
129150
writeliner.append(format_line_directory(dirname))
151+
writeliner.extend(format_line_table_header())
152+
130153
filedict_sorted = dict(sorted(filedict.items()))
131-
for filename, result in filedict_sorted.items():
132-
writeliner.append(format_line_file(filename, result))
154+
for filename, filedata in filedict_sorted.items():
155+
writeliner.append(format_line_file(filename, filedata))
133156

134157
with open(
135-
f"summarize_progress/dist/summarize_progress.md",
158+
f"summarize_progress/result.md",
136159
"w",
137160
) as file:
138161
file.writelines(writeliner)

Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,35 @@ all: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build an
5353
for file in *.po */*.po; do ln -f $$file $(LC_MESSAGES)/$$file; done
5454
. $(VENV)/bin/activate; $(MAKE) -C $(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D locale_dirs=locales -D language=$(LANGUAGE) -D gettext_compact=0' $(MODE)
5555

56+
.PHONY: build
57+
build: $(VENV)/bin/sphinx-build $(VENV)/bin/blurb clone ## Automatically build an html local version
58+
@$(eval target=$(filter-out $@,$(MAKECMDGOALS)))
59+
@if [ -z $(target) ]; then \
60+
echo "\x1B[1;31m""Please provide a file argument.""\x1B[m"; \
61+
exit 1; \
62+
fi
63+
@if [ "$(suffix $(target))" != ".po" ]; then \
64+
echo "\x1B[1;31m""Incorrect file extension. Only '.po' files are allowed.""\x1B[m"; \
65+
exit 1; \
66+
fi
67+
@if [[ ! -f "$(target)" ]] ; then \
68+
echo "\x1B[1;31m""ERROR: $(target) not exist.""\x1B[m"; \
69+
exit 1; \
70+
fi
71+
@mkdir -p $(LC_MESSAGES)
72+
@$(eval dir=`echo $(target) | xargs -n1 dirname`) ## Get dir
73+
# If the build target is in under directory
74+
# We should make direcotry in $(LC_MESSAGES) and link the file.
75+
@if [ $(dir) != "." ]; then \
76+
echo "mkdir -p $(LC_MESSAGES)/$(dir)"; \
77+
mkdir -p $(LC_MESSAGES)/$(dir); \
78+
echo "ln -f ./$(target) $(LC_MESSAGES)/$(target)"; \
79+
ln -f ./$(target) $(LC_MESSAGES)/$(target); \
80+
fi
81+
# Build
82+
@echo "----"
83+
@. $(VENV)/bin/activate; $(MAKE) -C $(CPYTHON_CLONE)/Doc/ SPHINXOPTS='-j$(JOBS) -D language=$(LANGUAGE) -D locale_dirs=locales -D gettext_compact=0' SOURCES='$(basename $(target)).rst' html
84+
5685
help:
5786
@python3 -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
5887

@@ -133,3 +162,7 @@ rm_cpython: ## Remove cloned cpython repo
133162
.PHONY: lint
134163
lint: $(VENV)/bin/sphinx-lint ## Run sphinx-lint
135164
$(VENV)/bin/sphinx-lint --enable default-role
165+
166+
# This allows us to accept extra arguments (by doing nothing when we get a job that doesn't match, rather than throwing an error)
167+
%:
168+
@:

README.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ the PSF for inclusion in the documentation.
8484
上請參考 https://gitforwindows.org/)
8585
- 一個 ``.po`` 檔的編輯器。推薦使用 `Poedit <https://poedit.net>`_,若熟悉 po 檔用一般文字編輯器亦可。
8686
- macOS 的使用者還需要先利用 `homebrew <https://brew.sh/index_zh-tw>`_ 安裝 gettext,屆時 Sphinx 會使用到。
87+
8788
.. code-block:: bash
8889
8990
brew install gettext
90-
9191
brew link gettext --force
92+
9293
- 安裝 pre-commit 自動在 commit 時檢查 ``.po`` 檔格式。
94+
9395
.. code-block:: bash
9496
9597
pip install pre-commit

0 commit comments

Comments
 (0)