Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 17 additions & 3 deletions generate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "gitpython",
# "potodo",
Expand All @@ -16,6 +17,7 @@
from jinja2 import Template

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

Expand All @@ -30,13 +32,23 @@
)
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True)
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
switcher_languages = switcher.get_languages()
for language, repo in repositories.get_languages_and_repos(devguide_dir):
if repo:
completion_number, translators_number = get_completion(clones_dir, repo)
visitors_number = visitors.get_number_of_visitors(language)
else:
completion_number, visitors_number = 0.0, 0
completion_progress.append((language, repo, completion_number, translators_number, visitors_number))
completion_progress.append(
(
language,
repo,
completion_number,
translators_number,
visitors_number,
switcher_languages[language],
)
)
print(completion_progress[-1])

template = Template(
Expand All @@ -58,13 +70,14 @@
</tr>
</thead>
<tbody>
{% for language, repo, completion, translators, visitors in completion_progress | sort(attribute=2) | reverse %}
{% for language, repo, completion, translators, visitors, in_switcher in completion_progress | sort(attribute=2) | reverse %}
<tr>
{% if repo %}
<td data-label="language">
<a href="https://github.com/{{ repo }}" target="_blank">
{{ language }}
{{ language -}}
</a>
{{- "*" if in_switcher else "" }}
</td>
<td data-label="visitors">
<a href="https://plausible.io/docs.python.org?filters=((contains,page,(/{{ language }}/)))" target="_blank">
Expand All @@ -84,6 +97,7 @@
{% endfor %}
</tbody>
</table>
<p>* Language is in the <a href="https://docs.python.org">docs.python.org</a> switcher.</p>
<p>Last updated at {{ generation_time.strftime('%A, %d %B %Y, %X %Z') }}.</p>
</body>
</html>
Expand Down
38 changes: 38 additions & 0 deletions switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Fetch languages in the https://docs.python.org language switcher.
Return a defaultdict mapping language codes to a Boolean indicating
whether it is in the language switcher.
"""

import tomllib
from collections import defaultdict

import requests


def get_languages() -> defaultdict[str, bool]:
# Languages missing from config.toml are not in production
in_prod = defaultdict(lambda: False)
data = requests.get(
"https://raw.githubusercontent.com/"
"python/docsbuild-scripts/refs/heads/main/config.toml",
timeout=10,
).text
languages = tomllib.loads(data)["languages"]
for code, language in languages.items():
code = code.lower().replace("_", "-")
# Languages in config.toml default to being in production
in_prod[code] = language.get("in_prod", True)
return in_prod


def main() -> None:
languages = get_languages()
print(languages)
for code in ("en", "pl", "ar", "zh-cn"):
print(f"{code}: {languages[code]}")


if __name__ == "__main__":
main()
Loading