Skip to content

Commit c680fdd

Browse files
authored
Add workflow info, contribution link and language name (#35)
* Add workflow info and contribution link * Remove type ignore (released upstream -- typeshed) * Add language names * Don't link from language name, move repo link as contrib link fallback
1 parent 3de9c0b commit c680fdd

6 files changed

+94
-19
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ repos:
3838
rev: v1.14.1
3939
hooks:
4040
- id: mypy
41-
additional_dependencies: [types-docutils, types-polib, types-requests]
41+
additional_dependencies: [types-docutils, types-polib>=1.2.0.20250114, types-requests]
4242

4343
ci:
4444
autoupdate_schedule: quarterly

contribute.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
pulling_from_transifex = ('zh-cn', 'pt-br', 'ja', 'uk', 'pl')
2+
3+
custom_contributing_links = {
4+
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
5+
'ko': 'https://www.flowdas.com/pages/python-docs-ko.html',
6+
'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',
7+
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/3.13/CONTRIBUTING.rst',
8+
'id': 'https://github.com/python/python-docs-id/blob/master/README.md#berkontribusi-untuk-menerjemahkan',
9+
'tr': 'https://github.com/python/python-docs-tr/blob/3.12/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
10+
'gr': 'https://github.com/pygreece/python-docs-gr/blob/3.12/CONTRIBUTING.md',
11+
}
12+
13+
14+
def get_contrib_link(language: str, repo: str | None) -> str | None:
15+
return (
16+
custom_contributing_links.get(language)
17+
or (
18+
language in pulling_from_transifex
19+
and 'https://explore.transifex.com/python-doc/python-newest/'
20+
)
21+
or (repo and f'https://github.com/{repo}')
22+
)
23+
24+
25+
if __name__ == '__main__':
26+
for code, repo in (
27+
('en', None),
28+
('pl', None),
29+
('ar', 'python/python-docs-ar'),
30+
('zh-cn', None),
31+
('id', None),
32+
):
33+
print(f'{code}: {get_contrib_link(code, repo)}')

generate.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
from datetime import datetime, timezone
1414
from pathlib import Path
1515
from tempfile import TemporaryDirectory
16-
from typing import Literal, cast
16+
from typing import cast, Literal
1717

1818
from git import Repo
1919
from jinja2 import Template
2020

21+
import contribute
2122
import repositories
2223
import build_status
2324
import visitors
@@ -27,7 +28,21 @@
2728

2829

2930
def get_completion_progress() -> (
30-
Iterator[tuple[str, str, float, int, str | Literal[False], int, bool, bool | None]]
31+
Iterator[
32+
tuple[
33+
str,
34+
str,
35+
str,
36+
float,
37+
int,
38+
str | Literal[False],
39+
int,
40+
bool,
41+
bool | None,
42+
bool,
43+
str | None,
44+
]
45+
]
3146
):
3247
with TemporaryDirectory() as clones_dir:
3348
Repo.clone_from(
@@ -49,23 +64,40 @@ def get_completion_progress() -> (
4964
['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True
5065
)
5166
languages_built = dict(build_status.get_languages())
52-
for lang, repo in repositories.get_languages_and_repos(devguide_dir):
67+
for lang, lang_name, repo in repositories.get_languages_and_repos(devguide_dir):
5368
built = lang in languages_built
5469
in_switcher = languages_built.get(lang)
70+
tx = lang in contribute.pulling_from_transifex
71+
contrib_link = contribute.get_contrib_link(lang, repo)
5572
if not repo:
56-
yield lang, cast(str, repo), 0.0, 0, False, 0, built, in_switcher
73+
yield (
74+
lang,
75+
lang_name,
76+
cast(str, repo),
77+
0.0,
78+
0,
79+
False,
80+
0,
81+
built,
82+
in_switcher,
83+
False,
84+
None,
85+
)
5786
continue
5887
completion, translators, translators_link = get_completion(clones_dir, repo)
5988
visitors_num = visitors.get_number_of_visitors(lang) if built else 0
6089
yield (
6190
lang,
91+
lang_name,
6292
repo,
6393
completion,
6494
translators,
6595
translators_link,
6696
visitors_num,
6797
built,
6898
in_switcher,
99+
tx,
100+
contrib_link,
69101
)
70102

71103

repositories.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
import re
22
from collections.abc import Iterator
33
from pathlib import Path
4+
from tempfile import TemporaryDirectory
45

56
from docutils import core
67
from docutils.nodes import table, row
8+
from git import Repo
79

810

9-
def get_languages_and_repos(devguide_dir: Path) -> Iterator[tuple[str, str | None]]:
11+
def get_languages_and_repos(
12+
devguide_dir: Path,
13+
) -> Iterator[tuple[str, str, str | None]]:
1014
translating = devguide_dir.joinpath('documentation/translating.rst').read_text()
1115
doctree = core.publish_doctree(translating)
1216

1317
for node in doctree.traverse(table):
1418
for row_node in node.traverse(row)[1:]:
1519
language = row_node[0].astext()
1620
repo = row_node[2].astext()
17-
language_match = re.match(r'.* \((.*)\)', language)
21+
language_match = re.match(r'(.*) \((.*)\)', language)
1822
if not language_match:
1923
raise ValueError(
2024
f'Expected a language code in brackets in devguide table, found {language}'
2125
)
22-
language_code = language_match.group(1).lower().replace('_', '-')
26+
language_name = language_match.group(1)
27+
language_code = language_match.group(2).lower().replace('_', '-')
2328
repo_match = re.match(':github:`GitHub <(.*)>`', repo)
24-
yield language_code, repo_match and repo_match.group(1)
29+
yield language_code, language_name, repo_match and repo_match.group(1)
30+
31+
32+
if __name__ == '__main__':
33+
with TemporaryDirectory() as directory:
34+
Repo.clone_from('https://github.com/python/devguide.git', directory, depth=1)
35+
for item in get_languages_and_repos(Path(directory)):
36+
print(item)

template.html.jinja

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,22 @@
99
<thead>
1010
<tr>
1111
<th>language</th>
12+
<th>contribute</th>
1213
<th>build</th>
1314
<th><a href="https://plausible.io/data-policy#how-we-count-unique-users-without-cookies" target="_blank">visitors</a></th>
1415
<th>translators</th>
1516
<th>completion</th>
1617
</tr>
1718
</thead>
1819
<tbody>
19-
{% for language, repo, completion, translators, translators_link, visitors, build, in_switcher in completion_progress | sort(attribute='2,3') | reverse %}
20+
{% 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 %}
2021
<tr>
21-
{% if repo %}
22-
<td data-label="language">
23-
<a href="https://github.com/{{ repo }}" target="_blank">
24-
{{ language }}
25-
</a>
22+
<td data-label="language">{{ language_name }} ({{ language }})</td>
23+
<td data-label="contribute">
24+
{% if contrib_link %}<a href="{{ contrib_link }}" target="_blank">{% endif %}
25+
{% if on_platform %}platform{% else %}repository{% endif %}
26+
{% if contrib_link %}</a>{% endif %}
2627
</td>
27-
{% else %}
28-
<td data-label="language">{{ language }}</td>
29-
{% endif %}
3028
<td data-label="build">
3129
{% if build %}
3230
<a href="https://docs.python.org/{{ language }}/" target="_blank">✓{% if in_switcher %} in switcher{% endif %}</a>

translators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_number_from_git_history(path: Path) -> int:
1919
def yield_from_headers(path: Path) -> Iterator[str]:
2020
for file in path.rglob('*.po'):
2121
try:
22-
header = pofile(file).header.splitlines() # type: ignore[call-overload] # https://github.com/python/typeshed/pull/13396
22+
header = pofile(file).header.splitlines()
2323
except IOError:
2424
continue
2525
if 'Translators:' not in header:

0 commit comments

Comments
 (0)