-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerate.py
More file actions
79 lines (70 loc) · 2.34 KB
/
generate.py
File metadata and controls
79 lines (70 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "gitpython",
# "potodo",
# "jinja2",
# "requests",
# "docutils",
# ]
# ///
import subprocess
from collections.abc import Iterator
from datetime import datetime, timezone
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import cast
from git import Repo
from jinja2 import Template
import repositories
import build_status
import visitors
from completion import branches_from_devguide, get_completion
generation_time = datetime.now(timezone.utc)
def get_completion_progress() -> (
Iterator[tuple[str, str, str, float, int, int, bool, bool | None]]
):
with TemporaryDirectory() as clones_dir:
Repo.clone_from(
'https://github.com/python/devguide.git',
devguide_dir := Path(clones_dir, 'devguide'),
depth=1,
)
latest_branch = branches_from_devguide(devguide_dir)[0]
Repo.clone_from(
'https://github.com/python/cpython.git',
Path(clones_dir, 'cpython'),
depth=1,
branch=latest_branch,
)
subprocess.run(
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True
)
subprocess.run(
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True
)
languages_built = dict(build_status.get_languages())
for lang, lang_name, repo in repositories.get_languages_and_repos(devguide_dir):
built = lang in languages_built
in_switcher = languages_built.get(lang)
if not repo:
yield lang, lang_name, cast(str, repo), 0.0, 0, 0, built, in_switcher
continue
completion, translators = get_completion(clones_dir, repo)
visitors_num = visitors.get_number_of_visitors(lang) if built else 0
yield (
lang,
lang_name,
repo,
completion,
translators,
visitors_num,
built,
in_switcher,
)
if __name__ == '__main__':
template = Template(Path('template.html.jinja').read_text())
output = template.render(
completion_progress=get_completion_progress(), generation_time=generation_time
)
Path('index.html').write_text(output)