Skip to content

Add workflow info, contribution link and language name #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 17, 2025
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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies: [types-docutils, types-polib, types-requests]
additional_dependencies: [types-docutils, types-polib>=1.2.0.20250114, types-requests]

ci:
autoupdate_schedule: quarterly
33 changes: 33 additions & 0 deletions contribute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
pulling_from_transifex = ('zh-cn', 'pt-br', 'ja', 'uk', 'pl')

custom_contributing_links = {
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
'ko': 'https://www.flowdas.com/pages/python-docs-ko.html',
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/3.13/README.rst#%E5%8F%83%E8%88%87%E7%BF%BB%E8%AD%AF',
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/3.13/CONTRIBUTING.rst',
'id': 'https://github.com/python/python-docs-id/blob/master/README.md#berkontribusi-untuk-menerjemahkan',
'tr': 'https://github.com/python/python-docs-tr/blob/3.12/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
'gr': 'https://github.com/pygreece/python-docs-gr/blob/3.12/CONTRIBUTING.md',
}


def get_contrib_link(language: str, repo: str | None) -> str | None:
return (
custom_contributing_links.get(language)
or (
language in pulling_from_transifex
and 'https://explore.transifex.com/python-doc/python-newest/'
)
or (repo and f'https://github.com/{repo}')
)


if __name__ == '__main__':
for code, repo in (
('en', None),
('pl', None),
('ar', 'python/python-docs-ar'),
('zh-cn', None),
('id', None),
):
print(f'{code}: {get_contrib_link(code, repo)}')
40 changes: 36 additions & 4 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from datetime import datetime, timezone
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import Literal, cast
from typing import cast, Literal

from git import Repo
from jinja2 import Template

import contribute
import repositories
import build_status
import visitors
Expand All @@ -27,7 +28,21 @@


def get_completion_progress() -> (
Iterator[tuple[str, str, float, int, str | Literal[False], int, bool, bool | None]]
Iterator[
tuple[
str,
str,
str,
float,
int,
str | Literal[False],
int,
bool,
bool | None,
bool,
str | None,
]
]
):
with TemporaryDirectory() as clones_dir:
Repo.clone_from(
Expand All @@ -49,23 +64,40 @@ def get_completion_progress() -> (
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True
)
languages_built = dict(build_status.get_languages())
for lang, repo in repositories.get_languages_and_repos(devguide_dir):
for lang, lang_name, repo in repositories.get_languages_and_repos(devguide_dir):
built = lang in languages_built
in_switcher = languages_built.get(lang)
tx = lang in contribute.pulling_from_transifex
contrib_link = contribute.get_contrib_link(lang, repo)
if not repo:
yield lang, cast(str, repo), 0.0, 0, False, 0, built, in_switcher
yield (
lang,
lang_name,
cast(str, repo),
0.0,
0,
False,
0,
built,
in_switcher,
False,
None,
)
continue
completion, translators, translators_link = get_completion(clones_dir, repo)
visitors_num = visitors.get_number_of_visitors(lang) if built else 0
yield (
lang,
lang_name,
repo,
completion,
translators,
translators_link,
visitors_num,
built,
in_switcher,
tx,
contrib_link,
)


Expand Down
20 changes: 16 additions & 4 deletions repositories.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
import re
from collections.abc import Iterator
from pathlib import Path
from tempfile import TemporaryDirectory

from docutils import core
from docutils.nodes import table, row
from git import Repo


def get_languages_and_repos(devguide_dir: Path) -> Iterator[tuple[str, str | None]]:
def get_languages_and_repos(
devguide_dir: Path,
) -> Iterator[tuple[str, str, str | None]]:
translating = devguide_dir.joinpath('documentation/translating.rst').read_text()
doctree = core.publish_doctree(translating)

for node in doctree.traverse(table):
for row_node in node.traverse(row)[1:]:
language = row_node[0].astext()
repo = row_node[2].astext()
language_match = re.match(r'.* \((.*)\)', language)
language_match = re.match(r'(.*) \((.*)\)', language)
if not language_match:
raise ValueError(
f'Expected a language code in brackets in devguide table, found {language}'
)
language_code = language_match.group(1).lower().replace('_', '-')
language_name = language_match.group(1)
language_code = language_match.group(2).lower().replace('_', '-')
repo_match = re.match(':github:`GitHub <(.*)>`', repo)
yield language_code, repo_match and repo_match.group(1)
yield language_code, language_name, repo_match and repo_match.group(1)


if __name__ == '__main__':
with TemporaryDirectory() as directory:
Repo.clone_from('https://github.com/python/devguide.git', directory, depth=1)
for item in get_languages_and_repos(Path(directory)):
print(item)
16 changes: 7 additions & 9 deletions template.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@
<thead>
<tr>
<th>language</th>
<th>contribute</th>
<th>build</th>
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies" target="_blank">visitors</a></th>
<th>translators</th>
<th>completion</th>
</tr>
</thead>
<tbody>
{% for language, repo, completion, translators, translators_link, visitors, build, in_switcher in completion_progress | sort(attribute='2,3') | reverse %}
{% for language, language_name, repo, completion, translators, translators_link, visitors, build, in_switcher, on_platform, contrib_link in completion_progress | sort(attribute='3,4') | reverse %}
<tr>
{% if repo %}
<td data-label="language">
<a href="https://github.com/{{ repo }}" target="_blank">
{{ language }}
</a>
<td data-label="language">{{ language_name }} ({{ language }})</td>
<td data-label="contribute">
{% if contrib_link %}<a href="{{ contrib_link }}" target="_blank">{% endif %}
{% if on_platform %}platform{% else %}repository{% endif %}
{% if contrib_link %}</a>{% endif %}
</td>
{% else %}
<td data-label="language">{{ language }}</td>
{% endif %}
<td data-label="build">
{% if build %}
<a href="https://docs.python.org/{{ language }}/" target="_blank">✓{% if in_switcher %} in switcher{% endif %}</a>
Expand Down
2 changes: 1 addition & 1 deletion translators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_number_from_git_history(path: Path) -> int:
def yield_from_headers(path: Path) -> Iterator[str]:
for file in path.rglob('*.po'):
try:
header = pofile(file).header.splitlines() # type: ignore[call-overload] # https://github.com/python/typeshed/pull/13396
header = pofile(file).header.splitlines()
except IOError:
continue
if 'Translators:' not in header:
Expand Down
Loading