Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 22 additions & 2 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 = list(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,
language in switcher_languages,
)
)
print(completion_progress[-1])

template = Template(
Expand All @@ -52,19 +64,27 @@
<thead>
<tr>
<th>language</th>
<th>build</th>
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies">visitors<a/></th>
<th>translators</th>
<th>completion</th>
</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 }}
</a>
</td>
<td data-label="build">
{% if in_switcher %}
<a href="https://docs.python.org/{{ language }}/">in switcher</a>
{% else %}
{% endif %}
</td>
<td data-label="visitors">
<a href="https://plausible.io/docs.python.org?filters=((contains,page,(/{{ language }}/)))" target="_blank">
Expand Down
6 changes: 3 additions & 3 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ th {
min-width: 50px;
box-sizing: border-box;
}
td:nth-child(2) {
td[data-label="visitors"] {
text-align: right;
}
td:last-child {
td[data-label="completion"] {
width: 100%;
}
@media screen and (max-width: 600px) {
Expand Down Expand Up @@ -56,7 +56,7 @@ td:last-child {
left: 10px;
position: absolute;
}
td:last-child {
td[data-label="completion"] {
width: inherit;
}
.progress-bar {
Expand Down
37 changes: 37 additions & 0 deletions switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""
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
from typing import Generator

import requests


def get_languages() -> Generator[str, None, None]:
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():
if language.get("in_prod", defaults["in_prod"]):
yield code.lower().replace("_", "-")


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


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