Skip to content

Commit 9242cb7

Browse files
committed
Add metadata.html
1 parent 358ff67 commit 9242cb7

File tree

3 files changed

+124
-7
lines changed

3 files changed

+124
-7
lines changed

generate.py

-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from jinja2 import Template
2626
from urllib3 import PoolManager
2727

28-
import build_warnings
2928
import build_status
3029
import contribute
3130
from visitors import get_number_of_visitors
@@ -73,14 +72,10 @@ def get_project_data(
7372
visitors_num = (
7473
get_number_of_visitors(language.code, PoolManager()) if built else 0
7574
)
76-
warnings = (
77-
build_warnings.number(clones_dir, repo, language.code) if completion else 0
78-
)
7975
else:
8076
completion = 0.0
8177
translators_data = TranslatorsData(0, False)
8278
visitors_num = 0
83-
warnings = 0
8479
branch = None
8580
return LanguageProjectData(
8681
language,
@@ -89,7 +84,6 @@ def get_project_data(
8984
completion,
9085
translators_data,
9186
visitors_num,
92-
warnings,
9387
built,
9488
in_switcher=languages_built.get(language.code),
9589
uses_platform=language.code in contribute.pulling_from_transifex,
@@ -105,7 +99,6 @@ class LanguageProjectData:
10599
completion: float
106100
translators: TranslatorsData
107101
visitors: int
108-
warnings: int
109102
built: bool
110103
in_switcher: bool | None
111104
uses_platform: bool

generate_metadata.py

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# /// script
2+
# requires-python = ">=3.11"
3+
# dependencies = [
4+
# "gitpython",
5+
# "potodo",
6+
# "jinja2",
7+
# "requests",
8+
# "docutils",
9+
# "sphinx",
10+
# "python-docs-theme",
11+
# "dacite",
12+
# ]
13+
# ///
14+
import concurrent.futures
15+
import itertools
16+
import logging
17+
import subprocess
18+
from collections.abc import Iterator, Sequence
19+
from datetime import datetime, timezone
20+
from json import loads
21+
from pathlib import Path
22+
from tempfile import TemporaryDirectory
23+
24+
import dacite
25+
from git import Repo
26+
from jinja2 import Template
27+
28+
import build_warnings
29+
from completion import branches_from_devguide
30+
from generate import LanguageProjectData
31+
from repositories import Language
32+
33+
generation_time = datetime.now(timezone.utc)
34+
35+
36+
def get_projects_metadata(
37+
completion_progress: Sequence[LanguageProjectData],
38+
) -> Iterator[int]:
39+
with TemporaryDirectory() as clones_dir:
40+
Repo.clone_from(
41+
'https://github.com/python/devguide.git',
42+
devguide_dir := Path(clones_dir, 'devguide'),
43+
depth=1,
44+
)
45+
latest_branch = branches_from_devguide(devguide_dir)[0]
46+
Repo.clone_from(
47+
'https://github.com/python/cpython.git',
48+
cpython_dir := Path(clones_dir, 'cpython'),
49+
depth=1,
50+
branch=latest_branch,
51+
)
52+
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
53+
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
54+
with concurrent.futures.ProcessPoolExecutor() as executor:
55+
return executor.map(
56+
get_metadata,
57+
*zip(*map(get_language_repo_and_completion, completion_progress)),
58+
itertools.repeat(clones_dir),
59+
)
60+
61+
62+
def get_metadata(
63+
language: Language, repo: str | None, completion: float, clones_dir: str
64+
) -> int:
65+
return (
66+
repo and completion and build_warnings.number(clones_dir, repo, language.code)
67+
) or 0
68+
69+
70+
def get_language_repo_and_completion(
71+
project: LanguageProjectData,
72+
) -> tuple[Language, str | None, float]:
73+
return project.language, project.repository, project.completion
74+
75+
76+
if __name__ == '__main__':
77+
logging.basicConfig(level=logging.INFO)
78+
logging.info(f'starting at {generation_time}')
79+
template = Template(Path('metadata.html.jinja').read_text())
80+
81+
completion_progress = [
82+
dacite.from_dict(LanguageProjectData, project)
83+
for project in loads(Path('index.json').read_text())
84+
]
85+
86+
output = template.render(
87+
metadata=zip(completion_progress, get_projects_metadata(completion_progress)),
88+
generation_time=generation_time,
89+
duration=(datetime.now(timezone.utc) - generation_time).seconds,
90+
)
91+
92+
Path('metadata.html').write_text(output)

metadata.html.jinja

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<html lang="en">
2+
<head>
3+
<title>Python Docs Translation Dashboard</title>
4+
<link rel="stylesheet" href="style.css">
5+
<meta charset="UTF-8">
6+
<base target="_blank">
7+
</head>
8+
<body>
9+
<h1>Python Docs Translation Dashboard</h1>
10+
<table>
11+
<thead>
12+
<tr>
13+
<th>language</th>
14+
<th>build warnings*</th>
15+
</tr>
16+
</thead>
17+
<tbody>
18+
{% for project, metadata in metadata | sort(attribute='0.completion,0.translators.number') | reverse %}
19+
<tr>
20+
<td data-label="language">{{ project.language.name }} ({{ project.language.code }})</td>
21+
<td data-label="warnings">
22+
{% if project.completion %}<a href="warnings-{{ project.language.code }}.txt">{{ metadata }}</a>{% else %}{{ metadata }}{% endif %}
23+
</td>
24+
</tr>
25+
{% endfor %}
26+
</tbody>
27+
</table>
28+
<p>* number of Sphinx build process warnings</p>
29+
<p>For more information about translations, see the <a href="https://devguide.python.org/documentation/translating/">Python Developer’s Guide</a>.</p>
30+
<p>Last updated at {{ generation_time.strftime('%A, %-d %B %Y, %-H:%M:%S %Z') }} (in {{ duration // 60 }}:{{ "{:02}".format(duration % 60) }} minutes).</p>
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)