Skip to content

Commit

Permalink
Merge branch 'python:3.12' into 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
isabellechiu authored Dec 5, 2023
2 parents f2a94b3 + 8fef8f1 commit 7951fd2
Show file tree
Hide file tree
Showing 178 changed files with 19,108 additions and 18,614 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
run: sudo apt-get install gettext

- name: Validate
run: VERSION=${{ github.event.pull_request.base.ref }} MODE=dummy make all
run: VERSION=${{ github.event.repository.default_branch }} MODE=dummy make all
28 changes: 28 additions & 0 deletions .github/workflows/summarize_progress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: summarize_progress

on:
schedule:
- cron: '30 23 * * 5'

jobs:
ci:
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

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Weekly Update -- Summarize Progress
142 changes: 140 additions & 2 deletions .scripts/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .scripts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python = "^3.10"
polib = "1.1.1"
googletrans = "3.1.0a0"
translate-toolkit = "3.8.1"

requests = "2.31.0"

[build-system]
requires = ["poetry-core"]
Expand Down
12 changes: 12 additions & 0 deletions .scripts/summarize_progress.sh
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
"
498 changes: 498 additions & 0 deletions .scripts/summarize_progress/dist/summarize_progress.md

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions .scripts/summarize_progress/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import re
import polib
import glob
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.
'''

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"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",
"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 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}"
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"]:
if issue["assignee"] is None:
continue

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), issue["assignee"]["login"]))

return result_list

def format_line_file(filename: str, result: str) -> str:
return f" - {filename.ljust(37, '-')}{result}\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] = 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 = []
summary_sorted = dict(sorted(summary.items()))
for dirname, filedict in summary_sorted.items():
writeliner.append(format_line_directory(dirname))
filedict_sorted = dict(sorted(filedict.items()))
for filename, result in filedict_sorted.items():
writeliner.append(format_line_file(filename, result))

with open(
f"summarize_progress/dist/summarize_progress.md",
"w",
) as file:
file.writelines(writeliner)
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ endif
mkdir -p "$$(dirname "$$PO")";\
if [ -f "$$PO" ];\
then\
case "$$POT" in\
*whatsnew*) msgmerge --lang=$(LANGUAGE) --backup=off --force-po --no-fuzzy-matching -U "$$PO" "$$POT" ;;\
*) msgmerge --lang=$(LANGUAGE) --backup=off --force-po -U "$$PO" "$$POT" ;;\
esac\
msgmerge --lang=$(LANGUAGE) --backup=off --force-po -U "$$PO" "$$POT";\
else\
msgcat --lang=$(LANGUAGE) -o "$$PO" "$$POT";\
fi\
Expand Down
9 changes: 5 additions & 4 deletions bugs.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Python 3.12\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-02-27 00:17+0000\n"
"POT-Creation-Date: 2023-11-05 09:50+0000\n"
"PO-Revision-Date: 2022-08-31 12:34+0800\n"
"Last-Translator: Steven Hsu <[email protected]>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
Expand Down Expand Up @@ -117,9 +117,10 @@ msgstr "給有意成為 Python 說明文件貢獻者的綜合指南。"

#: ../../bugs.rst:41
msgid ""
"`Documentation Translations <https://devguide.python.org/documenting/"
"#translating>`_"
msgstr "`說明文件翻譯 <https://devguide.python.org/documenting/#translating>`_"
"`Documentation Translations <https://devguide.python.org/documentation/"
"translating/>`_"
msgstr ""
"`說明文件翻譯 <https://devguide.python.org/documentation/translating/>`_"

#: ../../bugs.rst:42
msgid ""
Expand Down
Loading

0 comments on commit 7951fd2

Please sign in to comment.