Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions build_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
Fetch build status of languages in the https://docs.python.org.
Yield a tuple of language code and a Boolean indicating
whether it is in the language switcher.
"""

import tomllib
from collections.abc import Generator

import requests


def get_languages() -> Generator[tuple[str, bool]]:
data = requests.get(
'https://raw.githubusercontent.com/'
'python/docsbuild-scripts/refs/heads/main/config.toml',
timeout=10,
).text
config = tomllib.loads(data)
languages = config['languages']
defaults = config['defaults']
for code, language in languages.items():
language_code = code.lower().replace('_', '-')
in_switcher = language.get('in_prod', defaults['in_prod'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
defaults = config['defaults']
for code, language in languages.items():
language_code = code.lower().replace('_', '-')
in_switcher = language.get('in_prod', defaults['in_prod'])
for code, language in languages.items():
language_code = code.lower().replace('_', '-')
in_switcher = language.get('in_prod', True)

Copy link
Collaborator Author

@m-aciek m-aciek Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing! I agree that this suggestion improves readability. I'm concerned it doesn't honour https://github.com/python/docsbuild-scripts/blob/e4a8aff9772738a63d0945042777d18c3d926930/config.toml#L3; I was thinking if to propose a simplification upstream, but it makes the toml config file better self-describing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yield language_code, in_switcher


def main() -> None:
languages = {language: in_switcher for language, in_switcher in get_languages()}
print(languages)
for code in ('en', 'pl', 'ar', 'zh-cn', 'id'):
print(f'{code}: {code in languages} {languages.get(code)}')


if __name__ == '__main__':
main()
15 changes: 9 additions & 6 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from jinja2 import Template

import repositories
import switcher
import build_status
import visitors
from completion import branches_from_devguide, get_completion

Expand All @@ -41,7 +41,9 @@
subprocess.run(
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True
)
switcher_languages = list(switcher.get_languages())
languages_built = {
language: in_switcher for language, in_switcher in build_status.get_languages()
}
for language, repo in repositories.get_languages_and_repos(devguide_dir):
if repo:
completion_number, translators_number = get_completion(clones_dir, repo)
Expand All @@ -55,7 +57,8 @@
completion_number,
translators_number,
visitors_number,
language in switcher_languages,
language in languages_built,
languages_built.get(language),
)
)
print(completion_progress[-1])
Expand All @@ -80,7 +83,7 @@
</tr>
</thead>
<tbody>
{% for language, repo, completion, translators, visitors, in_switcher in completion_progress | sort(attribute='2,3') | reverse %}
{% for language, repo, completion, translators, visitors, build, in_switcher in completion_progress | sort(attribute='2,3') | reverse %}
<tr>
{% if repo %}
<td data-label="language">
Expand All @@ -92,8 +95,8 @@
<td data-label="language">{{ language }}</td>
{% endif %}
<td data-label="build">
{% if in_switcher %}
<a href="https://docs.python.org/{{ language }}/">in switcher</a>
{% if build %}
<a href="https://docs.python.org/{{ language }}/" target="_blank">✓ {% if in_switcher %}in switcher{% endif %}</a>
{% else %}
{% endif %}
Expand Down
36 changes: 0 additions & 36 deletions switcher.py

This file was deleted.

Loading