Repository navigation
Expand file tree
/
Copy pathgenerate.py
More file actions
136 lines (115 loc) · 4.19 KB
/
Copy pathgenerate.py
File metadata and controls
136 lines (115 loc) · 4.19 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
129
130
131
132
133
134
135
136
from __future__ import annotations
import concurrent.futures
import itertools
import json
import logging
import subprocess
from collections.abc import Iterator
from dataclasses import asdict, dataclass
from datetime import UTC, datetime
from pathlib import Path
from git import Repo
from jinja2 import Environment, FileSystemLoader
from urllib3 import PoolManager
import contribute
import translated_names
from completion import branches_from_peps, get_completion, release_cycle_from_peps
from repositories import Language, get_languages_and_repos
logger = logging.getLogger('pydocs-translation-dashboard')
generation_time = datetime.now(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
@property
def completion_score(self) -> float:
return self.completion + self.core_completion
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logger.info('starting at %s', generation_time)
Path('build').mkdir(parents=True, exist_ok=True)
completion_progress = list(get_completion_progress())
python_version = branches_from_peps()[0]
env = Environment(loader=FileSystemLoader('templates'))
index = env.get_template('index.html.jinja').render(
completion_progress=completion_progress,
python_version=python_version,
release_cycle_status=release_cycle_from_peps()[python_version]['status'],
generation_time=generation_time,
duration=(datetime.now(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)
)