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
@@ -37,7 +37,11 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
3737 )
3838 subprocess .run (['make' , '-C' , cpython_dir / 'Doc' , 'venv' ], check = True )
3939 subprocess .run (['make' , '-C' , cpython_dir / 'Doc' , 'gettext' ], check = True )
40- languages_built = dict (build_status .get_languages (PoolManager ()))
40+
41+ languages_built : dict [str , str ] = {
42+ language : translated_name
43+ for language , translated_name in build_status .get_languages (PoolManager ())
44+ }
4145
4246 with concurrent .futures .ThreadPoolExecutor () as executor :
4347 return executor .map (
@@ -51,7 +55,7 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
5155def get_project_data (
5256 language : Language ,
5357 repo : str | None ,
54- languages_built : dict [str , bool ],
58+ languages_built : dict [str , str ],
5559 clones_dir : str ,
5660) -> 'LanguageProjectData' :
5761 built = language .code in languages_built
@@ -62,6 +66,7 @@ def get_project_data(
6266 translators_data = TranslatorsData (0 , False )
6367 change = 0.0
6468 branch = ''
69+
6570 return LanguageProjectData (
6671 language ,
6772 repo ,
@@ -70,7 +75,7 @@ def get_project_data(
7075 change ,
7176 translators_data ,
7277 built ,
73- in_switcher = languages_built .get (language .code ),
78+ translated_name = languages_built .get (language .code , '' ),
7479 uses_platform = language .code in contribute .pulling_from_transifex ,
7580 contribution_link = contribute .get_contrib_link (language .code , repo ),
7681 )
@@ -85,24 +90,30 @@ class LanguageProjectData:
8590 change : float
8691 translators : TranslatorsData
8792 built : bool
88- in_switcher : bool | None
93+ translated_name : str
8994 uses_platform : bool
9095 contribution_link : str | None
9196
9297
9398if __name__ == '__main__' :
9499 logging .basicConfig (level = logging .INFO )
95100 logging .info (f'starting at { generation_time } ' )
96- template = Template ( Path ('template.html.jinja ' ).read_text () )
101+ Path ('build ' ).mkdir ( parents = True , exist_ok = True )
97102
98- output = template .render (
99- completion_progress = (completion_progress := list (get_completion_progress ())),
103+ completion_progress = list (get_completion_progress ())
104+ counts = get_counts (Path ('clones' , 'cpython' , 'Doc' , 'build' , 'gettext' ))
105+
106+ env = Environment (loader = FileSystemLoader ('templates' ))
107+ index = env .get_template ('index.html.jinja' ).render (
108+ completion_progress = completion_progress ,
100109 generation_time = generation_time ,
101110 duration = (datetime .now (timezone .utc ) - generation_time ).seconds ,
102- counts = get_counts (Path ('clones' , 'cpython' , 'Doc' , 'build' , 'gettext' )),
103111 )
104112
105- Path ('index.html' ).write_text (output )
106- Path ('index.json' ).write_text (
107- json .dumps (completion_progress , indent = 2 , default = asdict )
113+ Path ('build/style.css' ).write_bytes (Path ('src/style.css' ).read_bytes ())
114+ Path ('build/logo.png' ).write_bytes (Path ('src/logo.png' ).read_bytes ())
115+ Path ('build/index.html' ).write_text (index )
116+
117+ Path ('build/index.json' ).write_text (
118+ json .dumps ([asdict (project ) for project in completion_progress ], indent = 2 )
108119 )
0 commit comments