-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.12' into feature/upgrade-makefile
- Loading branch information
Showing
365 changed files
with
51,056 additions
and
45,265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: summarize_progress | ||
|
||
on: | ||
schedule: | ||
- cron: '30 23 * * 5' | ||
|
||
jobs: | ||
ci: | ||
if: github.repository == 'python/python-docs-zh-tw' | ||
runs-on: ubuntu-latest | ||
permissions: | ||
# Give the default GITHUB_TOKEN write permission to commit and push the | ||
# added or changed files to the repository. | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install poetry | ||
uses: abatilo/actions-poetry@v2 | ||
|
||
- name: Execute Check Process | ||
run: | | ||
chmod +x .scripts/summarize_progress.sh | ||
.scripts/summarize_progress.sh | ||
shell: bash | ||
|
||
|
||
- name: Checkout wiki code | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: ${{github.repository}}.wiki | ||
path: markdown | ||
|
||
- name: Copy content | ||
run: | | ||
cp .scripts/summarize_progress/result.md markdown/各檔案翻譯進度清單.md | ||
shell: bash | ||
|
||
- name: Commit wiki code | ||
uses: stefanzweifel/git-auto-commit-action@v5 | ||
with: | ||
commit_message: Weekly Update -- Summarize Progress | ||
repository: markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Install the pre-commit hooks below with | ||
# 'pre-commit install' | ||
|
||
# Auto-update the version of the hooks with | ||
# 'pre-commit autoupdate' | ||
|
||
repos: | ||
- repo: https://git.afpy.org/AFPy/powrap | ||
# there's no release tag in repo, use the latest commit hash id instead | ||
rev: a34a9fed116d24562fbe4bb8d456ade85f056c36 | ||
hooks: | ||
- id: powrap |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
WORK_DIR=.scripts | ||
cd $WORK_DIR | ||
|
||
source utils/install_poetry.sh | ||
|
||
poetry lock | ||
poetry install | ||
poetry run bash -c " | ||
python summarize_progress/main.py | ||
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
import re | ||
import polib | ||
import glob | ||
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. | ||
''' | ||
|
||
lines_tranlated = len(pofile.translated_entries()) | ||
lines_untranlated = len(pofile.untranslated_entries()) | ||
|
||
if lines_tranlated == 0: | ||
result = "❌" | ||
elif lines_untranlated == 0: | ||
result = "✅" | ||
else: | ||
lines_all = lines_tranlated + lines_untranlated | ||
progress = lines_tranlated / lines_all | ||
progress_percentage = round(progress * 100, 2) | ||
result = f"{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", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
} | ||
r = requests.get(url=url, headers=headers) | ||
result = r.json() | ||
|
||
return result["total_count"] | ||
|
||
|
||
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 "Translate" in the title | ||
3. Filter the issue if it have no correct filepath in the title | ||
Expected Output: | ||
[ ((dirname, filename), assignee_id, issue_url), ... ] | ||
''' | ||
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}" | ||
headers = { | ||
"Accept": "application/vnd.github+json", | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
} | ||
r = requests.get(url=url, headers=headers) | ||
result = r.json() | ||
|
||
result_list = [] | ||
for issue in result["items"]: | ||
assignee = issue["assignee"]["login"] if issue["assignee"] else "" | ||
|
||
title = issue["title"] | ||
if "翻譯" not in title and "translate" not in title.lower(): | ||
continue | ||
|
||
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(((dirname, filename), assignee, issue["html_url"])) | ||
|
||
return result_list | ||
|
||
|
||
def format_line_table_header() -> list: | ||
return [f"|Filename|Progress|Issue|Assignee|\r\n", | ||
f"|-------:|:-------|:----|:-------|\r\n"] | ||
|
||
|
||
def format_issue_link(url: str) -> str: | ||
return f"[{url.split('/')[-1]}]({url})" if len(url) > 0 else '' | ||
|
||
|
||
def format_line_file(filename: str, data: dict) -> str: | ||
return f"|`{filename}`|{data['progress']}|{format_issue_link(data['issue'])}|{data['assignee']}|\r\n" | ||
|
||
|
||
def format_line_directory(dirname: str) -> str: | ||
return f"## {dirname}\r\n" | ||
|
||
|
||
if __name__ == "__main__": | ||
issue_list = get_github_issues() | ||
|
||
''' | ||
Search all the po file in the directory, | ||
and record the translation progress of each files. | ||
''' | ||
BASE_DIR = Path("../") | ||
summary = {} | ||
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) | ||
|
||
summary.setdefault(dirname, {})[filename] = { | ||
'progress': entry_check(po), | ||
'issue': '', | ||
'assignee': '', | ||
} | ||
|
||
''' | ||
Unpack the open issue list, and add assignee after the progress | ||
''' | ||
for (category, filename), assignee, issue_url in issue_list: | ||
try: | ||
summary[category][filename]['issue'] = issue_url | ||
summary[category][filename]['assignee'] = assignee | ||
except KeyError: | ||
pass | ||
|
||
''' | ||
Adding Space for Formatting Markdown Link | ||
''' | ||
|
||
''' | ||
Format the lines that will write into the markdown file, | ||
also sort the directory name and file name. | ||
''' | ||
writeliner = [] | ||
summary_sorted = dict(sorted(summary.items())) | ||
for dirname, filedict in summary_sorted.items(): | ||
writeliner.append(format_line_directory(dirname)) | ||
writeliner.extend(format_line_table_header()) | ||
|
||
filedict_sorted = dict(sorted(filedict.items())) | ||
for filename, filedata in filedict_sorted.items(): | ||
writeliner.append(format_line_file(filename, filedata)) | ||
|
||
with open( | ||
f"summarize_progress/result.md", | ||
"w", | ||
) as file: | ||
file.writelines(writeliner) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.