-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenerate.py
More file actions
128 lines (108 loc) · 3.86 KB
/
generate.py
File metadata and controls
128 lines (108 loc) · 3.86 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
120
121
122
123
124
125
126
127
128
from __future__ import annotations
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 translated_names
import contribute
from completion import branches_from_peps, get_completion
from repositories import Language, get_languages_and_repos
generation_time = datetime.now(timezone.utc)
def get_completion_progress() -> Iterator[LanguageProjectData]:
clones_dir = Path('clones')
if not (devguide_dir := Path(clones_dir, 'devguide')).exists():
Repo.clone_from('https://github.com/python/devguide.git', devguide_dir, depth=1)
else:
Repo(devguide_dir).git.pull()
latest_branch = branches_from_peps()[0]
if not (cpython_dir := Path(clones_dir, 'cpython')).exists():
Repo.clone_from(
'https://github.com/python/cpython.git',
cpython_dir,
depth=1,
branch=latest_branch,
)
else:
(cpython_repo := Repo(cpython_dir)).git.fetch()
cpython_repo.git.switch(latest_branch)
cpython_repo.git.pull()
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'clean'], check=True)
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 translated_names.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:
core_complation, completion, branch, core_change, change = get_completion(
clones_dir, repo
)
else:
core_complation = completion = 0.0
core_change = change = 0.0
branch = ''
return LanguageProjectData(
language,
repo,
branch,
core_complation,
completion,
core_change,
change,
built,
translated_name=languages_built.get(language.code)
or translated_names.babel_autonym(language.code)
or '',
contribution_link=contribute.get_contrib_link(language.code, repo),
)
@dataclass(frozen=True)
class LanguageProjectData:
language: Language
repository: str | None
branch: str
core_completion: float
completion: float
core_change: float
change: float
built: bool
translated_name: str
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())
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)
)