8000 Update with Reviewer's Suggestion · rockleona/python-docs-zh-tw@5f8e511 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5f8e511

Browse files
committed
Update with Reviewer's Suggestion
1 parent 53986f2 commit 5f8e511

File tree

3 files changed

+86
-74
lines changed

3 files changed

+86
-74
lines changed

.github/workflows/summarize_progress.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ jobs:
1919

2020
- name: Execute Check Process
2121
run: |
22-
chmod +x .scripts/mark_file.sh
23-
.scripts/mark_file.sh
22+
chmod +x .scripts/summarize_progress.sh
23+
.scripts/summarize_progress.sh
2424
shell: bash
2525

2626
- uses: stefanzweifel/git-auto-commit-action@v5
2727
with:
28-
commit_message: Weekly Update -- Marking files
29-
28+
commit_message: Weekly Update -- Summarize Progress

.scripts/summarize_progress/dist/summarize_progress_20231129_005702.md renamed to .scripts/summarize_progress/dist/summarize_progress.md

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
- // - about.po-----------------------------✅
1+
- //
2+
- about.po-----------------------------✅
23
- bugs.po------------------------------✅
34
- contents.po--------------------------✅
45
- copyright.po-------------------------✅
56
- glossary.po--------------------------✅
67
- license.po---------------------------✅
78
- sphinx.po----------------------------✅
8-
- c-api/ - abstract.po--------------------------✅
9+
- c-api/
10+
- abstract.po--------------------------✅
911
- allocation.po------------------------✅
1012
- apiabiversion.po---------------------✅
1113
- arg.po-------------------------------Ongoing, 47.59 %
@@ -70,15 +72,18 @@
7072
- utilities.po-------------------------✅
7173
- veryhigh.po--------------------------Ongoing, 3.51 %
7274
- weakref.po---------------------------Ongoing, 8.33 %
73-
- distributing/ - index.po-----------------------------✅
74-
- extending/ - building.po--------------------------Ongoing, 22.22 %
75+
- distributing/
76+
- index.po-----------------------------✅
77+
- extending/
78+
- building.po--------------------------Ongoing, 22.22 %
7579
- embedding.po-------------------------Ongoing, 4.44 %
7680
- extending.po-------------------------Ongoing, 5.56 %
7781
- index.po-----------------------------✅
7882
- newtypes.po--------------------------Ongoing, 12.36 %
7983
- newtypes_tutorial.po-----------------Ongoing, 0.82 %
8084
- windows.po---------------------------❌
81-
- faq/ - design.po----------------------------✅
85+
- faq/
86+
- design.po----------------------------✅
8287
- extending.po-------------------------✅
8388
- general.po---------------------------✅
8489
- gui.po-------------------------------✅
@@ -87,7 +92,8 @@
8792
- library.po---------------------------✅
8893
- programming.po-----------------------Ongoing, 98.72 %
8994
- windows.po---------------------------✅
90-
- howto/ - annotations.po-----------------------✅
95+
- howto/
96+
- annotations.po-----------------------✅
9197
- argparse.po--------------------------Ongoing, 57.61 %, 💻 sweslo17
9298
- clinic.po----------------------------✅
9399
- cporting.po--------------------------Ongoing, 20.0 %
@@ -108,9 +114,12 @@
108114
- sorting.po---------------------------✅
109115
- unicode.po---------------------------Ongoing, 3.31 %
110116
- urllib2.po---------------------------Ongoing, 16.67 %
111-
- includes/ - wasm-notavail.po---------------------❌
112-
- installing/ - index.po-----------------------------✅
113-
- library/ - 2to3.po------------------------------Ongoing, 32.23 %
117+
- includes/
118+
- wasm-notavail.po---------------------❌
119+
- installing/
120+
- index.po-----------------------------✅
121+
- library/
122+
- 2to3.po------------------------------Ongoing, 32.23 %
114123
- __future__.po------------------------✅
115124
- __main__.po--------------------------Ongoing, 3.7 %
116125
- _thread.po---------------------------Ongoing, 9.62 %
@@ -425,7 +434,8 @@
425434
- zipimport.po-------------------------Ongoing, 8.33 %
426435
- zlib.po------------------------------✅
427436
- zoneinfo.po--------------------------Ongoing, 6.67 %
428-
- reference/ - compound_stmts.po--------------------Ongoing, 26.19 %
437+
- reference/
438+
- compound_stmts.po--------------------Ongoing, 26.19 %
429439
- datamodel.po-------------------------Ongoing, 34.96 %
430440
- executionmodel.po--------------------Ongoing, 31.63 %
431441
- expressions.po-----------------------Ongoing, 36.54 %
@@ -436,7 +446,8 @@
436446
- lexical_analysis.po------------------Ongoing, 46.73 %
437447
- simple_stmts.po----------------------Ongoing, 37.18 %
438448
- toplevel_components.po---------------✅
439-
- tutorial/ - appendix.po--------------------------✅
449+
- tutorial/
450+
- appendix.po--------------------------✅
440451
- appetite.po--------------------------✅
441452
- classes.po---------------------------✅
442453
- controlflow.po-----------------------✅
@@ -453,14 +464,16 @@
453464
- stdlib2.po---------------------------✅
454465
- venv.po------------------------------✅
455466
- whatnow.po---------------------------✅
456-
- using/ - cmdline.po---------------------------Ongoing, 18.35 %
467+
- using/
468+
- cmdline.po---------------------------Ongoing, 18.35 %
457469
- configure.po-------------------------Ongoing, 35.11 %
458470
- editors.po---------------------------Ongoing, 33.33 %
459471
- index.po-----------------------------✅
460472
- mac.po-------------------------------✅
461473
- unix.po------------------------------✅
462474
- windows.po---------------------------Ongoing, 26.48 %
463-
- whatsnew/ - 2.0.po-------------------------------Ongoing, 6.59 %
475+
- whatsnew/
476+
- 2.0.po-------------------------------Ongoing, 6.59 %
464477
- 2.1.po-------------------------------Ongoing, 12.23 %
465478
- 2.2.po-------------------------------Ongoing, 2.62 %
466479
- 2.3.po-------------------------------Ongoing, 4.91 %

.scripts/summarize_progress/main.py

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
import datetime
55
import requests
66

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+
'''
714

8-
def entry_check(pofile) -> str:
915
lines_tranlated = len(pofile.translated_entries())
1016
lines_untranlated = len(pofile.untranslated_entries())
1117

@@ -17,12 +23,16 @@ def entry_check(pofile) -> str:
1723
lines_all = lines_tranlated + lines_untranlated
1824
progress = lines_tranlated / lines_all
1925
progress_percentage = round(progress * 100, 2)
20-
result = f"Ongoing, {str(progress_percentage)} %"
26+
result = f"Ongoing, {progress_percentage} %"
2127

2228
return result
2329

2430

2531
def get_open_issues_count() -> int:
32+
'''
33+
Fetch GitHub API to get the number of OPEN ISSUES.
34+
'''
35+
2636
url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open"
2737
headers = {
2838
"Accept": "application/vnd.github+json",
@@ -35,6 +45,16 @@ def get_open_issues_count() -> int:
3545

3646

3747
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+
'''
3858
NUMBER_OF_ISSUES = get_open_issues_count()
3959

4060
url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open&per_page={NUMBER_OF_ISSUES}"
@@ -47,92 +67,72 @@ def get_github_issues() -> list:
4767

4868
result_list = []
4969
for issue in result["items"]:
50-
title_segments = issue["title"].split()
51-
52-
if len(title_segments) < 2:
53-
continue
54-
if title_segments[0] != "翻譯" and title_segments[0].lower() != "translate":
55-
continue
5670
if issue["assignee"] is None:
5771
continue
5872

59-
filename = title_segments[1].strip("`")
73+
title = issue["title"]
74+
if "翻譯" not in title and "translate" not in title.lower():
75+
continue
6076

61-
if re.fullmatch("[a-zA-z-]+/[a-zA-Z0-9._-]+.po", filename):
62-
filename_segments = filename.split("/")
63-
# print(filename_segments)
64-
elif re.fullmatch("[a-zA-z-]+/[a-zA-Z0-9._-]+", filename):
65-
filename_segments = filename.split("/")
66-
filename_segments[1] += ".po"
67-
else:
77+
match = re.search("(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
78+
if not match:
6879
continue
80+
81+
dirname, filename = match.group('dirname', 'filename')
82+
if not filename.endswith('.po'):
83+
filename += '.po'
6984

70-
result_list.append([filename_segments, issue["assignee"]["login"]])
85+
result_list.append(((dirname, filename), issue["assignee"]["login"]))
7186

7287
return result_list
7388

74-
75-
def format_line_file(filename, result) -> str:
89+
def format_line_file(filename: str, result: str) -> str:
7690
return f" - {filename.ljust(37, '-')}{result}\r\n"
7791

7892

79-
def format_line_directory(dirname) -> str:
80-
tmp = f"- {dirname}/\r"
81-
return tmp
93+
def format_line_directory(dirname: str) -> str:
94+
return f"- {dirname}/\r\n"
8295

8396

8497
if __name__ == "__main__":
8598
issue_list = get_github_issues()
8699

87-
directories = [
88-
"c-api",
89-
"distributing",
90-
"extending",
91-
"faq",
92-
"howto",
93-
"includes",
94-
"installing",
95-
"library",
96-
"reference",
97-
"tutorial",
98-
"using",
99-
"whatsnew",
100-
]
101-
100+
'''
101+
Search all the po file in the directory,
102+
and record the translation progress of each files.
103+
'''
104+
BASE_DIR = Path("../")
102105
summary = {}
103-
104-
file_list = glob.glob("./../**/*.po", recursive=True)
105-
file_list.sort()
106-
107-
for filepath in file_list:
108-
if len(filepath.split("/")) == 4: # in-dir files
109-
_, _, dirname, filename = filepath.split("/")
110-
else: # root dir files
111-
_, _, filename = filepath.split("/")
112-
dirname = "/"
113-
114-
if dirname not in summary:
115-
summary[dirname] = {}
116-
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 '/'
117110
po = polib.pofile(filepath)
118-
result = entry_check(po)
119-
summary[dirname][filename] = result
111+
summary.setdefault(dirname, {})[filename] = entry_check(po)
120112

113+
'''
114+
Unpack the open issue list, and add assignee after the progress
115+
'''
121116
for (category, filename), assignee in issue_list:
122117
try:
123118
summary[category][filename] += f", 💻 {assignee}"
124119
except KeyError:
125120
pass
126121

122+
'''
123+
Format the lines that will write into the markdown file,
124+
also sort the directory name and file name.
125+
'''
127126
writeliner = []
128-
for dirname, filedict in summary.items():
127+
summary_sorted = dict(sorted(summary.items()))
128+
for dirname, filedict in summary_sorted.items():
129129
writeliner.append(format_line_directory(dirname))
130-
for filename, result in filedict.items():
130+
filedict_sorted = dict(sorted(filedict.items()))
131+
for filename, result in filedict_sorted.items():
131132
writeliner.append(format_line_file(filename, result))
132133

133-
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
134134
with open(
135-
f"summarize_progress/dist/summarize_progress_{timestamp}.md",
135+
f"summarize_progress/dist/summarize_progress.md",
136136
"w",
137137
) as file:
138138
file.writelines(writeliner)

0 commit comments

Comments
 (0)
0