-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerate.py
More file actions
119 lines (101 loc) · 3.61 KB
/
generate.py
File metadata and controls
119 lines (101 loc) · 3.61 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import json
import concurrent.futures
import itertools
import logging
import subprocess
from collections.abc import Iterator
from dataclasses import dataclass, asdict
from datetime import datetime, timezone
from pathlib import Path
from git import Repo
from jinja2 import Environment, FileSystemLoader
from urllib3 import PoolManager
import build_status
import contribute
from completion import branches_from_devguide, get_completion, TranslatorsData
from counts import get_counts
from repositories import Language, get_languages_and_repos
generation_time = datetime.now(timezone.utc)
def get_completion_progress() -> Iterator['LanguageProjectData']:
clones_dir = Path('clones')
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',
cpython_dir := Path(clones_dir, 'cpython'),
depth=1,
branch=latest_branch,
)
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
languages_built: dict[str, str] = {
language: translated_name
for language, translated_name in build_status.get_languages(PoolManager())
}
with concurrent.futures.ThreadPoolExecutor() as executor:
return executor.map(
get_project_data,
*zip(*get_languages_and_repos(devguide_dir)),
itertools.repeat(languages_built),
itertools.repeat(clones_dir),
)
def get_project_data(
language: Language,
repo: str | None,
languages_built: dict[str, str],
clones_dir: str,
) -> 'LanguageProjectData':
built = language.code in languages_built
if repo:
completion, translators_data, branch, change = get_completion(clones_dir, repo)
else:
completion = 0.0
translators_data = TranslatorsData(0, False)
change = 0.0
branch = ''
return LanguageProjectData(
language,
repo,
branch,
completion,
change,
translators_data,
built,
translated_name=languages_built.get(language.code, ''),
uses_platform=language.code in contribute.pulling_from_transifex,
contribution_link=contribute.get_contrib_link(language.code, repo),
)
@dataclass(frozen=True)
class LanguageProjectData:
language: Language
repository: str | None
branch: str
completion: float
change: float
translators: TranslatorsData
built: bool
translated_name: str
uses_platform: bool
contribution_link: str | None
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logging.info(f'starting at {generation_time}')
Path('build').mkdir(parents=True, exist_ok=True)
completion_progress = list(get_completion_progress())
counts = get_counts(Path('clones', 'cpython', 'Doc', 'build', 'gettext'))
env = Environment(loader=FileSystemLoader('templates'))
index = env.get_template('index.html.jinja').render(
completion_progress=completion_progress,
generation_time=generation_time,
duration=(datetime.now(timezone.utc) - generation_time).seconds,
)
Path('build/style.css').write_bytes(Path('src/style.css').read_bytes())
Path('build/logo.png').write_bytes(Path('src/logo.png').read_bytes())
Path('build/index.html').write_text(index)
Path('build/index.json').write_text(
json.dumps([asdict(project) for project in completion_progress], indent=2)
)