Skip to content
Prev Previous commit
Update with Reviewer's Suggestion
  • Loading branch information
rockleona committed Nov 29, 2023
commit 5f8e5112e7399afe039f92b6100c79b834ec7bae
7 changes: 3 additions & 4 deletions .github/workflows/summarize_progress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ jobs:

- name: Execute Check Process
run: |
chmod +x .scripts/mark_file.sh
.scripts/mark_file.sh
chmod +x .scripts/summarize_progress.sh
.scripts/summarize_progress.sh
shell: bash

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Weekly Update -- Marking files

commit_message: Weekly Update -- Summarize Progress
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
- // - about.po-----------------------------✅
- //
- about.po-----------------------------✅
- bugs.po------------------------------✅
- contents.po--------------------------✅
- copyright.po-------------------------✅
- glossary.po--------------------------✅
- license.po---------------------------✅
- sphinx.po----------------------------✅
- c-api/ - abstract.po--------------------------✅
- c-api/
- abstract.po--------------------------✅
- allocation.po------------------------✅
- apiabiversion.po---------------------✅
- arg.po-------------------------------Ongoing, 47.59 %
Expand Down Expand Up @@ -70,15 +72,18 @@
- utilities.po-------------------------✅
- veryhigh.po--------------------------Ongoing, 3.51 %
- weakref.po---------------------------Ongoing, 8.33 %
- distributing/ - index.po-----------------------------✅
- extending/ - building.po--------------------------Ongoing, 22.22 %
- distributing/
- index.po-----------------------------✅
- extending/
- building.po--------------------------Ongoing, 22.22 %
- embedding.po-------------------------Ongoing, 4.44 %
- extending.po-------------------------Ongoing, 5.56 %
- index.po-----------------------------✅
- newtypes.po--------------------------Ongoing, 12.36 %
- newtypes_tutorial.po-----------------Ongoing, 0.82 %
- windows.po---------------------------❌
- faq/ - design.po----------------------------✅
- faq/
- design.po----------------------------✅
- extending.po-------------------------✅
- general.po---------------------------✅
- gui.po-------------------------------✅
Expand All @@ -87,7 +92,8 @@
- library.po---------------------------✅
- programming.po-----------------------Ongoing, 98.72 %
- windows.po---------------------------✅
- howto/ - annotations.po-----------------------✅
- howto/
- annotations.po-----------------------✅
- argparse.po--------------------------Ongoing, 57.61 %, 💻 sweslo17
- clinic.po----------------------------✅
- cporting.po--------------------------Ongoing, 20.0 %
Expand All @@ -108,9 +114,12 @@
- sorting.po---------------------------✅
- unicode.po---------------------------Ongoing, 3.31 %
- urllib2.po---------------------------Ongoing, 16.67 %
- includes/ - wasm-notavail.po---------------------❌
- installing/ - index.po-----------------------------✅
- library/ - 2to3.po------------------------------Ongoing, 32.23 %
- includes/
- wasm-notavail.po---------------------❌
- installing/
- index.po-----------------------------✅
- library/
- 2to3.po------------------------------Ongoing, 32.23 %
- __future__.po------------------------✅
- __main__.po--------------------------Ongoing, 3.7 %
- _thread.po---------------------------Ongoing, 9.62 %
Expand Down Expand Up @@ -425,7 +434,8 @@
- zipimport.po-------------------------Ongoing, 8.33 %
- zlib.po------------------------------✅
- zoneinfo.po--------------------------Ongoing, 6.67 %
- reference/ - compound_stmts.po--------------------Ongoing, 26.19 %
- reference/
- compound_stmts.po--------------------Ongoing, 26.19 %
- datamodel.po-------------------------Ongoing, 34.96 %
- executionmodel.po--------------------Ongoing, 31.63 %
- expressions.po-----------------------Ongoing, 36.54 %
Expand All @@ -436,7 +446,8 @@
- lexical_analysis.po------------------Ongoing, 46.73 %
- simple_stmts.po----------------------Ongoing, 37.18 %
- toplevel_components.po---------------✅
- tutorial/ - appendix.po--------------------------✅
- tutorial/
- appendix.po--------------------------✅
- appetite.po--------------------------✅
- classes.po---------------------------✅
- controlflow.po-----------------------✅
Expand All @@ -453,14 +464,16 @@
- stdlib2.po---------------------------✅
- venv.po------------------------------✅
- whatnow.po---------------------------✅
- using/ - cmdline.po---------------------------Ongoing, 18.35 %
- using/
- cmdline.po---------------------------Ongoing, 18.35 %
- configure.po-------------------------Ongoing, 35.11 %
- editors.po---------------------------Ongoing, 33.33 %
- index.po-----------------------------✅
- mac.po-------------------------------✅
- unix.po------------------------------✅
- windows.po---------------------------Ongoing, 26.48 %
- whatsnew/ - 2.0.po-------------------------------Ongoing, 6.59 %
- whatsnew/
- 2.0.po-------------------------------Ongoing, 6.59 %
- 2.1.po-------------------------------Ongoing, 12.23 %
- 2.2.po-------------------------------Ongoing, 2.62 %
- 2.3.po-------------------------------Ongoing, 4.91 %
Expand Down
114 changes: 57 additions & 57 deletions .scripts/summarize_progress/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
import datetime
import requests

from pathlib import Path


def entry_check(pofile: polib.POFile) -> str:
'''
Check the po file with how many entries are translated or not.
'''

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

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

return result


def get_open_issues_count() -> int:
'''
Fetch GitHub API to get the number of OPEN ISSUES.
'''

url = f"https://api.github.com/search/issues?q=repo:python/python-docs-zh-tw+type:issue+state:open"
headers = {
"Accept": "application/vnd.github+json",
Expand All @@ -35,6 +45,16 @@ def get_open_issues_count() -> int:


def get_github_issues() -> list:
'''
Fetch GitHub API to collect the infomation of OPEN ISSUES,
including issue title and assignee.

Steps:
1. Fetch GitHub API and get open issue list
2. Filter the issue if it have no assignee
3. Filter the issue if it have no "Translate" in the title
4. Filter the issue if it have no correct filepath in the title
'''
NUMBER_OF_ISSUES = get_open_issues_count()

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

result_list = []
for issue in result["items"]:
title_segments = issue["title"].split()

if len(title_segments) < 2:
continue
if title_segments[0] != "翻譯" and title_segments[0].lower() != "translate":
continue
if issue["assignee"] is None:
continue

filename = title_segments[1].strip("`")
title = issue["title"]
if "翻譯" not in title and "translate" not in title.lower():
continue

if re.fullmatch("[a-zA-z-]+/[a-zA-Z0-9._-]+.po", filename):
filename_segments = filename.split("/")
# print(filename_segments)
elif re.fullmatch("[a-zA-z-]+/[a-zA-Z0-9._-]+", filename):
filename_segments = filename.split("/")
filename_segments[1] += ".po"
else:
match = re.search("(?P<dirname>[^\s`][a-zA-z-]+)/(?P<filename>[a-zA-Z0-9._-]+(.po)?)", title)
if not match:
continue

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

result_list.append([filename_segments, issue["assignee"]["login"]])
result_list.append(((dirname, filename), issue["assignee"]["login"]))

return result_list


def format_line_file(filename, result) -> str:
def format_line_file(filename: str, result: str) -> str:
return f" - {filename.ljust(37, '-')}{result}\r\n"


def format_line_directory(dirname) -> str:
tmp = f"- {dirname}/\r"
return tmp
def format_line_directory(dirname: str) -> str:
return f"- {dirname}/\r\n"


if __name__ == "__main__":
issue_list = get_github_issues()

directories = [
"c-api",
"distributing",
"extending",
"faq",
"howto",
"includes",
"installing",
"library",
"reference",
"tutorial",
"using",
"whatsnew",
]

'''
Search all the po file in the directory,
and record the translation progress of each files.
'''
BASE_DIR = Path("../")
summary = {}

file_list = glob.glob("./../**/*.po", recursive=True)
file_list.sort()

for filepath in file_list:
if len(filepath.split("/")) == 4: # in-dir files
_, _, dirname, filename = filepath.split("/")
else: # root dir files
_, _, filename = filepath.split("/")
dirname = "/"

if dirname not in summary:
summary[dirname] = {}

for filepath in glob.glob(str(BASE_DIR / "**/*.po"), recursive=True):
path = Path(filepath)
filename = path.name
dirname = path.parent.name if path.parent.name != BASE_DIR.name else '/'
po = polib.pofile(filepath)
result = entry_check(po)
summary[dirname][filename] = result
summary.setdefault(dirname, {})[filename] = entry_check(po)

'''
Unpack the open issue list, and add assignee after the progress
'''
for (category, filename), assignee in issue_list:
try:
summary[category][filename] += f", 💻 {assignee}"
except KeyError:
pass

'''
Format the lines that will write into the markdown file,
also sort the directory name and file name.
'''
writeliner = []
for dirname, filedict in summary.items():
summary_sorted = dict(sorted(summary.items()))
for dirname, filedict in summary_sorted.items():
writeliner.append(format_line_directory(dirname))
for filename, result in filedict.items():
filedict_sorted = dict(sorted(filedict.items()))
for filename, result in filedict_sorted.items():
writeliner.append(format_line_file(filename, result))

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