99from pathlib import Path
1010
1111from git import Repo
12- from jinja2 import Template
12+ from jinja2 import Environment , FileSystemLoader
1313from urllib3 import PoolManager
1414
1515import build_status
1616import contribute
17- from completion import branches_from_devguide , get_completion , TranslatorsData
18- from counts import get_counts
17+ from completion import branches_from_devguide , get_completion
1918from repositories import Language , get_languages_and_repos
2019
2120generation_time = datetime .now (timezone .utc )
@@ -37,7 +36,11 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
3736 )
3837 subprocess .run (['make' , '-C' , cpython_dir / 'Doc' , 'venv' ], check = True )
3938 subprocess .run (['make' , '-C' , cpython_dir / 'Doc' , 'gettext' ], check = True )
40- languages_built = dict (build_status .get_languages (PoolManager ()))
39+
40+ languages_built : dict [str , str ] = {
41+ language : translated_name
42+ for language , translated_name in build_status .get_languages (PoolManager ())
43+ }
4144
4245 with concurrent .futures .ThreadPoolExecutor () as executor :
4346 return executor .map (
@@ -51,26 +54,25 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
5154def get_project_data (
5255 language : Language ,
5356 repo : str | None ,
54- languages_built : dict [str , bool ],
57+ languages_built : dict [str , str ],
5558 clones_dir : str ,
5659) -> 'LanguageProjectData' :
5760 built = language .code in languages_built
5861 if repo :
59- completion , translators_data , branch , change = get_completion (clones_dir , repo )
62+ completion , branch , change = get_completion (clones_dir , repo )
6063 else :
6164 completion = 0.0
62- translators_data = TranslatorsData (0 , False )
6365 change = 0.0
6466 branch = ''
67+
6568 return LanguageProjectData (
6669 language ,
6770 repo ,
6871 branch ,
6972 completion ,
7073 change ,
71- translators_data ,
7274 built ,
73- in_switcher = languages_built .get (language .code ),
75+ translated_name = languages_built .get (language .code , '' ),
7476 uses_platform = language .code in contribute .pulling_from_transifex ,
7577 contribution_link = contribute .get_contrib_link (language .code , repo ),
7678 )
@@ -83,26 +85,30 @@ class LanguageProjectData:
8385 branch : str
8486 completion : float
8587 change : float
86- translators : TranslatorsData
8788 built : bool
88- in_switcher : bool | None
89+ translated_name : str
8990 uses_platform : bool
9091 contribution_link : str | None
9192
9293
9394if __name__ == '__main__' :
9495 logging .basicConfig (level = logging .INFO )
9596 logging .info (f'starting at { generation_time } ' )
96- template = Template ( Path ('template.html.jinja ' ).read_text () )
97+ Path ('build ' ).mkdir ( parents = True , exist_ok = True )
9798
98- output = template .render (
99- completion_progress = (completion_progress := list (get_completion_progress ())),
99+ completion_progress = list (get_completion_progress ())
100+
101+ env = Environment (loader = FileSystemLoader ('templates' ))
102+ index = env .get_template ('index.html.jinja' ).render (
103+ completion_progress = completion_progress ,
100104 generation_time = generation_time ,
101105 duration = (datetime .now (timezone .utc ) - generation_time ).seconds ,
102- counts = get_counts (Path ('clones' , 'cpython' , 'Doc' , 'build' , 'gettext' )),
103106 )
104107
105- Path ('index.html' ).write_text (output )
106- Path ('index.json' ).write_text (
107- json .dumps (completion_progress , indent = 2 , default = asdict )
108+ Path ('build/style.css' ).write_bytes (Path ('src/style.css' ).read_bytes ())
109+ Path ('build/logo.png' ).write_bytes (Path ('src/logo.png' ).read_bytes ())
110+ Path ('build/index.html' ).write_text (index )
111+
112+ Path ('build/index.json' ).write_text (
113+ json .dumps ([asdict (project ) for project in completion_progress ], indent = 2 )
108114 )
0 commit comments