-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathgenerate.py
More file actions
114 lines (99 loc) · 3.48 KB
/
Copy pathgenerate.py
File metadata and controls
114 lines (99 loc) · 3.48 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
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 types import SimpleNamespace
from git import Repo
from jinja2 import Template
from urllib3 import PoolManager
import build_status
import contribute
from completion import branches_from_devguide, get_stats, TranslatorsData
from repositories import Language, get_languages_and_repos
from word_count import get_word_count
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(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, bool],
clones_dir: str,
) -> 'LanguageProjectData':
built = language.code in languages_built
if repo:
stats, translators_data, branch, change = get_stats(clones_dir, repo)
template = Template(Path('language.html.jinja').read_text())
Path(f'{language.code}.html').write_text(
template.render(stats=stats, language=language)
)
else:
stats = SimpleNamespace(completion=0.0)
translators_data = TranslatorsData(0, False)
change = 0.0
branch = ''
return LanguageProjectData(
language,
repo,
branch,
stats.completion,
change,
translators_data,
built,
in_switcher=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
in_switcher: bool | None
uses_platform: bool
contribution_link: str | None
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
logging.info(f'starting at {generation_time}')
template = Template(Path('template.html.jinja').read_text())
output = template.render(
completion_progress=(completion_progress := list(get_completion_progress())),
generation_time=generation_time,
duration=(datetime.now(timezone.utc) - generation_time).seconds,
word_count=get_word_count(Path('clones', 'cpython', 'Doc', 'build', 'gettext')),
)
Path('index.html').write_text(output)
Path('index.json').write_text(
json.dumps(completion_progress, indent=2, default=asdict)
)