Skip to content

Commit 59a620a

Browse files
authored
Check all languages against latest source strings (python-docs-translations#6)
* Check all against local gettext build * Remove branch info as superfluous * Clone CPython repo and build gettext * Add Sphinx dependency * Add blurb dependency * Fix clone path * Debug log * Install gettext in the workflow * Format with black * Skip OSError handling -- covered by potodo now * Improve styling * Simplify scan after upstream change * Remove unused import * Fix: break the versions loop when cloned * Make cpython docs venv * fix: bring back outer temp directory * revert format on template * update call argument name * Remove custom potodo version and a note from template * Install GNU Gettext in Read the Docs, reorder arguments * Remove sudo call in Read the Docs command * Add gettext with apt_packages (test) * convert command to jobs * move plugin add to install group * Align visitors number to right * Revert "Align visitors number to right" This reverts commit 77be670. * Add missing import * Update completion.py: fix reference * Add missing CPython clone code
1 parent 20705e5 commit 59a620a

File tree

4 files changed

+44
-30
lines changed

4 files changed

+44
-30
lines changed

.github/workflows/update.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
python-version: "3.x"
1818
- uses: astral-sh/setup-uv@v4
1919
- uses: actions/checkout@v4
20+
- run: sudo apt-get install -y gettext
2021
- run: uv run generate.py # generates "index.html"
2122
- run: mkdir -p build && cp index.html style.css build
2223
- name: Deploy 🚀

.readthedocs.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ build:
88
os: ubuntu-24.04
99
tools:
1010
python: "3"
11-
commands:
12-
- asdf plugin add uv
13-
- asdf install uv latest
14-
- asdf global uv latest
15-
- uv run generate.py
16-
- mkdir -p _readthedocs/html
17-
- mv index.html style.css _readthedocs/html
11+
apt_packages:
12+
- gettext
13+
jobs:
14+
post_checkout: []
15+
install:
16+
- asdf plugin add uv
17+
- asdf install uv latest
18+
pre_build:
19+
- asdf global uv latest
20+
build:
21+
html:
22+
- uv run generate.py
23+
- mkdir -p _readthedocs/html
24+
- mv index.html style.css _readthedocs/html

completion.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import pathlib
2-
import shutil
1+
from functools import cache
2+
from pathlib import Path
3+
from tempfile import TemporaryDirectory
34

45
import git
56
from potodo import potodo
67
import requests
78

8-
9+
@cache
910
def branches_from_devguide() -> list[str]:
1011
r = requests.get(
1112
"https://raw.githubusercontent.com/"
@@ -18,21 +19,21 @@ def branches_from_devguide() -> list[str]:
1819
]
1920

2021

21-
def get_completion_and_branch(tmpdir: str, language: str) -> tuple[float, str]:
22-
clone_path = pathlib.Path(tmpdir, language)
22+
def get_completion(clones_dir: str, language: str) -> float:
23+
clone_path = Path(clones_dir, language)
2324

2425
for branch in branches_from_devguide():
2526
try:
26-
git.Repo.clone_from(f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch)
27+
git.Repo.clone_from(
28+
f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch
29+
)
2730
except git.GitCommandError:
2831
print(f'failed to clone {language} {branch}')
2932
continue
30-
try:
31-
completion = potodo.scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion
32-
except OSError:
33-
print(f'failed to scan {language} {branch}')
34-
shutil.rmtree(clone_path)
35-
continue
3633
else:
3734
break
38-
return completion, branch
35+
with TemporaryDirectory() as tmpdir:
36+
completion = potodo.merge_and_scan_path(
37+
clone_path, pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'), merge_path=Path(tmpdir), hide_reserved=False, api_url=''
38+
).completion
39+
return completion

generate.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,37 @@
66
# "requests",
77
# ]
88
# ///
9+
import subprocess
910
from datetime import datetime, timezone
11+
from pathlib import Path
1012
from tempfile import TemporaryDirectory
1113

14+
from git import Repo
1215
from jinja2 import Template
1316

14-
import completion
1517
import visitors
18+
from completion import branches_from_devguide, get_completion
1619

1720
completion_progress = []
1821
generation_time = datetime.now(timezone.utc)
1922

20-
with TemporaryDirectory() as tmpdir:
23+
with TemporaryDirectory() as clones_dir:
24+
Repo.clone_from(
25+
f'https://github.com/python/cpython.git', Path(clones_dir, 'cpython'), depth=1, branch=branches_from_devguide()[0]
26+
)
27+
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True)
28+
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
2129
for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'):
22-
completion_number, branch = completion.get_completion_and_branch(tmpdir, language)
30+
completion_number = get_completion(clones_dir, language)
2331
visitors_number = visitors.get_number_of_visitors(language)
24-
completion_progress.append((language, completion_number, branch, visitors_number))
32+
completion_progress.append((language, completion_number, visitors_number))
2533
print(completion_progress[-1])
2634

2735
template = Template("""
2836
<html lang="en">
2937
<head>
30-
<title>Python Docs Translation Dashboard</title>
31-
<link rel="stylesheet" href="style.css">
38+
<title>Python Docs Translation Dashboard</title>
39+
<link rel="stylesheet" href="style.css">
3240
</head>
3341
<body>
3442
<h1>Python Docs Translation Dashboard</h1>
@@ -37,12 +45,11 @@
3745
<tr>
3846
<th>language</th>
3947
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies">visitors<a/></th>
40-
<th>branch</th>
4148
<th>completion</th>
4249
</tr>
4350
</thead>
4451
<tbody>
45-
{% for language, completion, branch, visitors in completion_progress | sort(attribute=1) | reverse %}
52+
{% for language, completion, visitors in completion_progress | sort(attribute=1) | reverse %}
4653
<tr>
4754
<td data-label="language">
4855
<a href="https://github.com/python/python-docs-{{ language }}" target="_blank">
@@ -54,7 +61,6 @@
5461
{{ '{:,}'.format(visitors) }}
5562
</a>
5663
</td>
57-
<td data-label="branch">{{ branch }}</td>
5864
<td data-label="completion">
5965
<div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div>
6066
</td>
@@ -63,7 +69,6 @@
6369
</tbody>
6470
</table>
6571
<p>Last updated at {{ generation_time.strftime('%A, %d %B %Y, %X %Z') }}.</p>
66-
<p>Note that the completion value is based on files available in language Git repository and <a href="https://github.com/m-aciek/pydocs-translation-dashboard/issues/2" target="_blank">may not include</a> e.g. resources which translation hasn't yet started.</p>
6772
</body>
6873
</html>
6974
""")

0 commit comments

Comments
 (0)