Skip to content

Commit 8926d9e

Browse files
committed
Add GitHub workflows
1 parent c9b6af0 commit 8926d9e

13 files changed

Lines changed: 381 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Translation Issue Report
2+
description: File a translation issue report
3+
title: "[Typo]: "
4+
labels: ["translation"]
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: |
9+
Thanks for taking the time to fill out this translation issue report!
10+
- type: input
11+
id: version
12+
attributes:
13+
label: Python Version
14+
description: Which version of the Python documentation covers this issue?
15+
placeholder: ex. 3.12
16+
validations:
17+
required: true
18+
- type: input
19+
id: url
20+
attributes:
21+
label: Docs Page
22+
description: What is the url of the page containing the issue?
23+
placeholder: https://docs.python.org/3/about.html
24+
validations:
25+
required: true
26+
- type: textarea
27+
id: ru-original
28+
attributes:
29+
label: Original Translation
30+
description: Which translated paragraph in Russian contains the issue?
31+
validations:
32+
required: true
33+
- type: textarea
34+
id: en-original
35+
attributes:
36+
label: Original Docs Paragraph
37+
description: Which original paragraph in English contains the issue?
38+
validations:
39+
required: false
40+
- type: textarea
41+
id: ru-suggested
42+
attributes:
43+
label: Suggested Fix
44+
description: What is your suggested fix?
45+
validations:
46+
required: true

.github/scripts/build.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -u
5+
set -o pipefail
6+
7+
error() {
8+
while read -r line; do
9+
echo
10+
echo ::error::"$line"
11+
done
12+
}
13+
14+
cd cpython/Doc || exit 1
15+
mkdir -p locales/"$LOCALE"/
16+
ln -sfn "$(realpath ../../docs)" locales/"$LOCALE"/LC_MESSAGES
17+
pip3 install -q -r requirements.txt
18+
sphinx-build -b dummy -d build/doctrees -j auto -D language=$LOCALE -D gettext_compact=0 -E --keep-going -W . build/html 2> >(error)

.github/scripts/commit.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
cd docs || exit 1
6+
git config user.email "github-actions[bot]@users.noreply.github.com"
7+
git config user.name "github-actions[bot]"
8+
if ! git status -s|grep '\.po'; then
9+
echo "Nothing to commit"
10+
exit 0
11+
fi
12+
git add .
13+
git commit -m '[po] auto sync'
14+
git push
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
"""Please note that this script requires a Transifex API token to run."""
2+
import glob
3+
import subprocess
4+
from functools import partial
5+
from pathlib import Path
6+
import re
7+
import os
8+
9+
run = partial(subprocess.run, check=True)
10+
11+
12+
def init_project():
13+
run(["tx", "init"])
14+
15+
16+
def add_files(project_name: str):
17+
run(
18+
[
19+
"tx",
20+
"add",
21+
"remote",
22+
"--file-filter",
23+
"trans/<lang>/<resource_slug>.<ext>",
24+
f"https://www.transifex.com/python-doc/{project_name}/dashboard/",
25+
]
26+
)
27+
28+
29+
FILTER_PATTERN = re.compile(
30+
r"^(?P<prefix>file_filter( *)=( *))(?P<resource>.+)$", re.MULTILINE
31+
)
32+
33+
34+
def name_replacer(match: re.Match[str]):
35+
prefix, resource = match.group("prefix", "resource")
36+
override_prefix = prefix.replace("file_filter", "trans.zh_CN")
37+
pattern = (
38+
resource.replace("trans/<lang>/", "")
39+
.replace("glossary_", "glossary")
40+
.replace("--", "/")
41+
.replace("_", "?")
42+
)
43+
matches = list(glob.glob(pattern.replace(".po", ".rst")))
44+
if not matches:
45+
print("missing", pattern)
46+
return f"{prefix}{resource}\n{override_prefix}{pattern.replace('?', '_')}"
47+
elif len(matches) == 1:
48+
filename = matches[0].replace(".rst", ".po").replace("\\", "/")
49+
else:
50+
raise ValueError("multi match", resource, pattern, matches)
51+
return f"{prefix}{resource}\n{override_prefix}{filename}"
52+
53+
54+
def patch_config(path: str):
55+
tx_config_path = Path(".tx", "config")
56+
57+
config_content = tx_config_path.read_text("utf-8")
58+
59+
cwd = os.getcwd()
60+
os.chdir(path)
61+
config_content = FILTER_PATTERN.sub(name_replacer, config_content)
62+
config_content = re.sub(r'replace_edited_strings.*\n','', config_content)
63+
config_content = re.sub(r'keep_translations.*\n','', config_content)
64+
config_content = re.sub(r'0\ntrans\.ru.*\n','0\n', config_content)
65+
config_content = config_content.replace(' =','=')
66+
os.chdir(cwd)
67+
68+
tx_config_path.write_text(config_content, "utf-8")
69+
70+
71+
if __name__ == "__main__":
72+
from argparse import ArgumentParser
73+
74+
parser = ArgumentParser()
75+
76+
parser.add_argument("--token", default="")
77+
parser.add_argument("--project-name", required=True)
78+
parser.add_argument("--doc-path", required=True)
79+
80+
params = parser.parse_args()
81+
82+
if params.token:
83+
os.environ["TX_TOKEN"] = params.token
84+
85+
init_project()
86+
add_files(params.project_name)
87+
patch_config(params.doc_path)

.github/scripts/prepare.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash

.github/scripts/tx_stat.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import json
2+
import os
3+
import urllib.request
4+
from datetime import datetime
5+
6+
key = os.environ.get('TX_TOKEN')
7+
project = os.environ.get('TX_PROJECT')
8+
9+
url = "https://rest.api.transifex.com/resource_language_stats?filter[project]=o%3Apython-doc%3Ap%3A{}&filter[language]=l%3Aru".format(project)
10+
11+
headers = {
12+
"accept": "application/vnd.api+json",
13+
"authorization": "Bearer " + key
14+
}
15+
16+
total = 0
17+
translated = 0
18+
19+
while(url):
20+
request = urllib.request.Request(url=url,headers=headers)
21+
22+
with urllib.request.urlopen(request) as response:
23+
data = json.loads(response.read().decode("utf-8"))
24+
url = data['links'].get('next')
25+
for resourse in data['data']:
26+
translated = translated + resourse['attributes']['translated_strings']
27+
total = total + resourse['attributes']['total_strings']
28+
29+
p = '{:.2%}'.format(translated/total)
30+
print(json.dumps({
31+
'translation':p,
32+
'updated_at':datetime.utcnow().isoformat(timespec='seconds') + 'Z',
33+
}))

.github/scripts/update.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -u
4+
5+
cd cpython || exit 1
6+
7+
# Restore git timestamp for enabling build cache
8+
rev=HEAD
9+
for f in $(git ls-tree -r -t --full-name --name-only "$rev" Doc) ; do
10+
touch -d $(git log --pretty=format:%cI -1 "$rev" -- "$f") "$f";
11+
done
12+
13+
cd ..
14+
cd docs || exit 1
15+
16+
# Restore git timestamp for enabling build cache
17+
rev=HEAD
18+
for f in $(git ls-tree -r -t --full-name --name-only "$rev") ; do
19+
touch -d $(git log --pretty=format:%cI -1 "$rev" -- "$f") "$f";
20+
done
21+
22+
$(realpath ../tx) pull --languages "$LOCALE" -t --use-git-timestamps --workers 25 --silent

.github/workflows/python-310.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: python-310
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
schedule:
9+
- cron: "22 * * * *"
10+
11+
jobs:
12+
sync:
13+
uses: ./.github/workflows/sync.yml
14+
with:
15+
version: "3.10"
16+
tx_project: "python-310"
17+
secrets: inherit
18+

.github/workflows/python-311.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: python-311
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
schedule:
9+
- cron: "32 * * * *"
10+
11+
jobs:
12+
sync:
13+
uses: ./.github/workflows/sync.yml
14+
with:
15+
version: "3.11"
16+
tx_project: "python-311"
17+
secrets: inherit
18+

.github/workflows/python-312.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: python-312
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- master
8+
schedule:
9+
- cron: "42 * * * *"
10+
11+
jobs:
12+
sync:
13+
uses: ./.github/workflows/sync.yml
14+
with:
15+
version: "3.12"
16+
tx_project: "python-312"
17+
secrets: inherit

0 commit comments

Comments
 (0)