|
9 | 9 | # ] |
10 | 10 | # /// |
11 | 11 | import subprocess |
| 12 | +from collections.abc import Iterator |
12 | 13 | from datetime import datetime, timezone |
13 | 14 | from pathlib import Path |
14 | 15 | from tempfile import TemporaryDirectory |
|
24 | 25 | completion_progress = [] |
25 | 26 | generation_time = datetime.now(timezone.utc) |
26 | 27 |
|
27 | | -with TemporaryDirectory() as clones_dir: |
28 | | - Repo.clone_from( |
29 | | - 'https://github.com/python/devguide.git', |
30 | | - devguide_dir := Path(clones_dir, 'devguide'), |
31 | | - depth=1, |
32 | | - ) |
33 | | - latest_branch = branches_from_devguide(devguide_dir)[0] |
34 | | - Repo.clone_from( |
35 | | - 'https://github.com/python/cpython.git', |
36 | | - Path(clones_dir, 'cpython'), |
37 | | - depth=1, |
38 | | - branch=latest_branch, |
39 | | - ) |
40 | | - subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True) |
41 | | - subprocess.run( |
42 | | - ['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True |
43 | | - ) |
44 | | - languages_built = dict(build_status.get_languages()) |
45 | | - for language, repo in repositories.get_languages_and_repos(devguide_dir): |
46 | | - built_on_docs_python_org = language in languages_built |
47 | | - if repo: |
| 28 | + |
| 29 | +def get_completion_progress() -> ( |
| 30 | + Iterator[tuple[str, str, float, int, int, bool, bool | None]] |
| 31 | +): |
| 32 | + with TemporaryDirectory() as clones_dir: |
| 33 | + Repo.clone_from( |
| 34 | + 'https://github.com/python/devguide.git', |
| 35 | + devguide_dir := Path(clones_dir, 'devguide'), |
| 36 | + depth=1, |
| 37 | + ) |
| 38 | + latest_branch = branches_from_devguide(devguide_dir)[0] |
| 39 | + Repo.clone_from( |
| 40 | + 'https://github.com/python/cpython.git', |
| 41 | + Path(clones_dir, 'cpython'), |
| 42 | + depth=1, |
| 43 | + branch=latest_branch, |
| 44 | + ) |
| 45 | + subprocess.run( |
| 46 | + ['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True |
| 47 | + ) |
| 48 | + subprocess.run( |
| 49 | + ['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True |
| 50 | + ) |
| 51 | + languages_built = dict(build_status.get_languages()) |
| 52 | + for language, repo in repositories.get_languages_and_repos(devguide_dir): |
| 53 | + built_on_docs_python_org = language in languages_built |
| 54 | + in_switcher = languages_built.get(language) |
| 55 | + if not repo: |
| 56 | + yield language, repo, 0.0, 0, 0, built_on_docs_python_org, in_switcher |
48 | 57 | completion_number, translators_number = get_completion(clones_dir, repo) |
49 | 58 | if built_on_docs_python_org: |
50 | 59 | visitors_number = visitors.get_number_of_visitors(language) |
51 | 60 | else: |
52 | 61 | visitors_number = 0 |
53 | | - else: |
54 | | - completion_number, translators_number, visitors_number = 0.0, 0, 0 |
55 | | - completion_progress.append( |
56 | | - ( |
| 62 | + yield ( |
57 | 63 | language, |
58 | 64 | repo, |
59 | 65 | completion_number, |
60 | 66 | translators_number, |
61 | 67 | visitors_number, |
62 | 68 | built_on_docs_python_org, |
63 | | - languages_built.get(language), # in switcher |
| 69 | + in_switcher, |
64 | 70 | ) |
65 | | - ) |
66 | | - print(completion_progress[-1]) |
| 71 | + |
67 | 72 |
|
68 | 73 | template = Template(Path('template.html').read_text()) |
69 | 74 |
|
70 | 75 | output = template.render( |
71 | | - completion_progress=completion_progress, generation_time=generation_time |
| 76 | + completion_progress=get_completion_progress(), generation_time=generation_time |
72 | 77 | ) |
73 | 78 |
|
74 | 79 | Path('index.html').write_text(output) |
0 commit comments