Skip to content

Commit 83aef06

Browse files
Merge remote-tracking branch 'origin/main' into tests
# Conflicts: # build_status.py # translators.py
2 parents 399250b + 7725b22 commit 83aef06

17 files changed

+337
-336
lines changed

.github/workflows/update.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
- run: sudo apt-get install -y gettext
2222
- run: pip install -r requirements.txt
2323
- run: uv run generate.py # generates index.html and index.json
24-
- run: mkdir -p build && cp index.* style.css build
2524
- name: Deploy 🚀
2625
if: github.event_name != 'pull_request'
2726
uses: JamesIves/github-pages-deploy-action@v4
@@ -55,10 +54,9 @@ jobs:
5554
if: github.event_name == 'pull_request'
5655
run: |
5756
curl -Lo index.html-public https://github.com/python-docs-translations/dashboard/raw/refs/heads/gh-pages/index.html
58-
diff --color=always -u index.html-public index.html || :
59-
cat index.html
57+
diff --color=always -u index.html-public build/index.html || :
58+
cat build/index.html
6059
- run: uv run generate_metadata.py # generates metadata.html
61-
- run: cp metadata.html warnings* build
6260
- name: Deploy metadata view 🚀
6361
if: github.event_name != 'pull_request'
6462
uses: JamesIves/github-pages-deploy-action@v4

.gitignore

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
index.html
2-
metadata.html
3-
warnings-*.txt
1+
build
42
clones
3+
venv

build_status.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
2-
Fetch build status of languages in the https://docs.python.org.
2+
Fetch translated names of languages.
33
4-
Yield a tuple of language code and a Boolean indicating
5-
whether it is in the language switcher.
4+
Yield a tuple of language code and a string with the translated name.
65
"""
76

87
import tomllib
@@ -11,13 +10,13 @@
1110
from urllib3 import PoolManager
1211

1312

14-
def get_languages(http: PoolManager) -> Iterator[tuple[str, bool]]:
13+
def get_languages(http: PoolManager) -> Iterator[tuple[str, str]]:
1514
data = http.request(
1615
'GET',
1716
'https://raw.githubusercontent.com/python/docsbuild-scripts/refs/heads/main/config.toml',
1817
).data
1918
config = tomllib.loads(data.decode())
2019
for code, language in config['languages'].items():
2120
language_code = code.lower().replace('_', '-')
22-
in_switcher = language.get('in_prod', config['defaults']['in_prod'])
23-
yield language_code, in_switcher
21+
translated_name = language.get('translated_name')
22+
yield language_code, translated_name

build_warnings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ def number(clones_dir: str, repo: str, language_code: str) -> int:
3333
f'./sphinxbuild/{language_code}', # outputdir
3434
)
3535
)
36-
copyfile(warning_file, f'warnings-{language_code}.txt')
36+
copyfile(warning_file, f'build/warnings-{language_code}.txt')
3737
return len(findall('ERROR|WARNING', Path(warning_file).read_text()))

completion.py

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import json
2-
from dataclasses import dataclass
32
from functools import cache
43
from pathlib import Path
54
from tempfile import TemporaryDirectory
6-
from typing import Literal
75

86
import git
97
from potodo import potodo
108

11-
import translators
12-
139

1410
@cache
1511
def branches_from_devguide(devguide_dir: Path) -> list[str]:
@@ -22,9 +18,7 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
2218
]
2319

2420

25-
def get_completion(
26-
clones_dir: str, repo: str
27-
) -> tuple[float, 'TranslatorsData', str, float]:
21+
def get_completion(clones_dir: str, repo: str) -> tuple[float, str, float]:
2822
clone_path = Path(clones_dir, 'translations', repo)
2923
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + [
3024
'master',
@@ -36,13 +30,9 @@ def get_completion(
3630
)
3731
except git.GitCommandError:
3832
print(f'failed to clone {repo} {branch}')
39-
translators_data = TranslatorsData(0, False)
4033
branch = ''
4134
continue
4235
else:
43-
translators_number = translators.get_number(clone_path)
44-
translators_link = translators.get_link(clone_path, repo, branch)
45-
translators_data = TranslatorsData(translators_number, translators_link)
4636
break
4737
path_for_merge = Path(clones_dir, 'rebased_translations', repo)
4838
completion = potodo.merge_and_scan_path(
@@ -77,10 +67,4 @@ def get_completion(
7767

7868
change = completion - month_ago_completion
7969

80-
return completion, translators_data, branch, change
81-
82-
83-
@dataclass(frozen=True)
84-
class TranslatorsData:
85-
number: int
86-
link: str | Literal[False]
70+
return completion, branch, change

generate.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99
from pathlib import Path
1010

1111
from git import Repo
12-
from jinja2 import Template
12+
from jinja2 import Environment, FileSystemLoader
1313
from urllib3 import PoolManager
1414

1515
import build_status
1616
import contribute
17-
from completion import branches_from_devguide, get_completion, TranslatorsData
18-
from counts import get_counts
17+
from completion import branches_from_devguide, get_completion
1918
from repositories import Language, get_languages_and_repos
2019

2120
generation_time = datetime.now(timezone.utc)
@@ -37,7 +36,11 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
3736
)
3837
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
3938
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
40-
languages_built = dict(build_status.get_languages(PoolManager()))
39+
40+
languages_built: dict[str, str] = {
41+
language: translated_name
42+
for language, translated_name in build_status.get_languages(PoolManager())
43+
}
4144

4245
with concurrent.futures.ThreadPoolExecutor() as executor:
4346
return executor.map(
@@ -51,26 +54,25 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
5154
def get_project_data(
5255
language: Language,
5356
repo: str | None,
54-
languages_built: dict[str, bool],
57+
languages_built: dict[str, str],
5558
clones_dir: str,
5659
) -> 'LanguageProjectData':
5760
built = language.code in languages_built
5861
if repo:
59-
completion, translators_data, branch, change = get_completion(clones_dir, repo)
62+
completion, branch, change = get_completion(clones_dir, repo)
6063
else:
6164
completion = 0.0
62-
translators_data = TranslatorsData(0, False)
6365
change = 0.0
6466
branch = ''
67+
6568
return LanguageProjectData(
6669
language,
6770
repo,
6871
branch,
6972
completion,
7073
change,
71-
translators_data,
7274
built,
73-
in_switcher=languages_built.get(language.code),
75+
translated_name=languages_built.get(language.code, ''),
7476
uses_platform=language.code in contribute.pulling_from_transifex,
7577
contribution_link=contribute.get_contrib_link(language.code, repo),
7678
)
@@ -83,26 +85,30 @@ class LanguageProjectData:
8385
branch: str
8486
completion: float
8587
change: float
86-
translators: TranslatorsData
8788
built: bool
88-
in_switcher: bool | None
89+
translated_name: str
8990
uses_platform: bool
9091
contribution_link: str | None
9192

9293

9394
if __name__ == '__main__':
9495
logging.basicConfig(level=logging.INFO)
9596
logging.info(f'starting at {generation_time}')
96-
template = Template(Path('template.html.jinja').read_text())
97+
Path('build').mkdir(parents=True, exist_ok=True)
9798

98-
output = template.render(
99-
completion_progress=(completion_progress := list(get_completion_progress())),
99+
completion_progress = list(get_completion_progress())
100+
101+
env = Environment(loader=FileSystemLoader('templates'))
102+
index = env.get_template('index.html.jinja').render(
103+
completion_progress=completion_progress,
100104
generation_time=generation_time,
101105
duration=(datetime.now(timezone.utc) - generation_time).seconds,
102-
counts=get_counts(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
103106
)
104107

105-
Path('index.html').write_text(output)
106-
Path('index.json').write_text(
107-
json.dumps(completion_progress, indent=2, default=asdict)
108+
Path('build/style.css').write_bytes(Path('src/style.css').read_bytes())
109+
Path('build/logo.png').write_bytes(Path('src/logo.png').read_bytes())
110+
Path('build/index.html').write_text(index)
111+
112+
Path('build/index.json').write_text(
113+
json.dumps([asdict(project) for project in completion_progress], indent=2)
108114
)

generate_metadata.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import dacite
1111
from git import Repo
12-
from jinja2 import Template
12+
from jinja2 import Environment, FileSystemLoader
1313
from urllib3 import request
1414

1515
import build_warnings
@@ -55,20 +55,20 @@ def get_language_repo_and_completion(
5555
if __name__ == '__main__':
5656
logging.basicConfig(level=logging.INFO)
5757
logging.info(f'starting at {generation_time}')
58-
template = Template(Path('metadata.html.jinja').read_text())
59-
if (index_path := Path('index.json')).exists():
60-
index_json = loads(Path('index.json').read_text())
58+
env = Environment(loader=FileSystemLoader('templates'))
59+
if (index_path := Path('build/index.json')).exists():
60+
index_json = loads(Path('build/index.json').read_text())
6161
else:
6262
index_json = request('GET', argv[1]).json()
6363

6464
completion_progress = [
6565
dacite.from_dict(LanguageProjectData, project) for project in index_json
6666
]
6767

68-
output = template.render(
68+
output = env.get_template('metadata.html.jinja').render(
6969
metadata=zip(completion_progress, get_projects_metadata(completion_progress)),
7070
generation_time=generation_time,
7171
duration=(datetime.now(timezone.utc) - generation_time).seconds,
7272
)
7373

74-
Path('metadata.html').write_text(output)
74+
Path('build/metadata.html').write_text(output)

metadata.html.jinja

Lines changed: 0 additions & 42 deletions
This file was deleted.

sphinx_lint.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
def store_and_count_failures(clones_dir: str, repo: str, language_code: str) -> int:
99
failed_checks = list(chain.from_iterable(yield_failures(clones_dir, repo)))
10-
filepath = Path(f'warnings-lint-{language_code}.txt')
11-
filepath.write_text('\n'.join([str(c) for c in failed_checks]))
10+
prefix = f'{Path(clones_dir, "rebased_translations", repo)}/'
11+
log = '\n'.join(
12+
map(lambda check: check.removeprefix(prefix), map(str, failed_checks))
13+
)
14+
filepath = Path(f'build/warnings-lint-{language_code}.txt')
15+
filepath.write_text(log)
1216
return len(failed_checks)
1317

1418

src/logo.png

12.9 KB
Loading

0 commit comments

Comments
 (0)