Skip to content

Commit 81954c2

Browse files
committed
Build status
1 parent 2e752d9 commit 81954c2

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed

build_status.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Fetch build status of languages in the https://docs.python.org.
3+
4+
Yield a tuple of language code and a Boolean indicating
5+
whether it is in the language switcher.
6+
"""
7+
8+
import tomllib
9+
from collections.abc import Generator
10+
11+
import requests
12+
13+
14+
def get_languages() -> Generator[tuple[str, str]]:
15+
data = requests.get(
16+
'https://raw.githubusercontent.com/'
17+
'python/docsbuild-scripts/refs/heads/main/config.toml',
18+
timeout=10,
19+
).text
20+
config = tomllib.loads(data)
21+
languages = config['languages']
22+
defaults = config['defaults']
23+
for code, language in languages.items():
24+
language_code = code.lower().replace('_', '-')
25+
switcher = language.get('in_prod', defaults['in_prod'])
26+
yield language_code, switcher
27+
28+
29+
def main() -> None:
30+
languages = {language: switcher for language, switcher in get_languages()}
31+
print(languages)
32+
for code in ('en', 'pl', 'ar', 'zh-cn', 'id'):
33+
print(f'{code}: {code in languages and languages[code]}')
34+
35+
36+
if __name__ == '__main__':
37+
main()

generate.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from jinja2 import Template
1818

1919
import repositories
20-
import switcher
20+
import build_status
2121
import visitors
2222
from completion import branches_from_devguide, get_completion
2323

@@ -41,7 +41,7 @@
4141
subprocess.run(
4242
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True
4343
)
44-
switcher_languages = list(switcher.get_languages())
44+
switcher_languages = {language: switcher for language, switcher in build_status.get_languages()}
4545
for language, repo in repositories.get_languages_and_repos(devguide_dir):
4646
if repo:
4747
completion_number, translators_number = get_completion(clones_dir, repo)
@@ -56,6 +56,7 @@
5656
translators_number,
5757
visitors_number,
5858
language in switcher_languages,
59+
switcher_languages.get(language),
5960
)
6061
)
6162
print(completion_progress[-1])
@@ -80,7 +81,7 @@
8081
</tr>
8182
</thead>
8283
<tbody>
83-
{% for language, repo, completion, translators, visitors, in_switcher in completion_progress | sort(attribute='2,3') | reverse %}
84+
{% for language, repo, completion, translators, visitors, build, in_switcher in completion_progress | sort(attribute='2,3') | reverse %}
8485
<tr>
8586
{% if repo %}
8687
<td data-label="language">
@@ -92,8 +93,8 @@
9293
<td data-label="language">{{ language }}</td>
9394
{% endif %}
9495
<td data-label="build">
95-
{% if in_switcher %}
96-
<a href="https://docs.python.org/{{ language }}/">in switcher</a>
96+
{% if build %}
97+
<a href="https://docs.python.org/{{ language }}/" target="_blank">✓{% if switcher %}in switcher{% endif %}</a>
9798
{% else %}
9899
99100
{% endif %}

switcher.py

-36
This file was deleted.

0 commit comments

Comments
 (0)