Skip to content

Commit 806f242

Browse files
committed
Get list of repositories from devguide
1 parent 59a620a commit 806f242

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

completion.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ def branches_from_devguide() -> list[str]:
1919
]
2020

2121

22-
def get_completion(clones_dir: str, language: str) -> float:
23-
clone_path = Path(clones_dir, language)
24-
25-
for branch in branches_from_devguide():
22+
def get_completion(clones_dir: str, repo: str) -> float:
23+
clone_path = Path(clones_dir, repo)
24+
for branch in branches_from_devguide() + ['master']:
2625
try:
2726
git.Repo.clone_from(
28-
f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch
27+
f'https://github.com/{repo}.git', clone_path, depth=1, branch=branch
2928
)
3029
except git.GitCommandError:
31-
print(f'failed to clone {language} {branch}')
30+
print(f'failed to clone {repo} {branch}')
3231
continue
3332
else:
3433
break

generate.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# "potodo",
55
# "jinja2",
66
# "requests",
7+
# "docutils",
78
# ]
89
# ///
910
import subprocess
@@ -14,6 +15,7 @@
1415
from git import Repo
1516
from jinja2 import Template
1617

18+
import repositories
1719
import visitors
1820
from completion import branches_from_devguide, get_completion
1921

@@ -26,10 +28,13 @@
2628
)
2729
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True)
2830
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
29-
for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'):
30-
completion_number = get_completion(clones_dir, language)
31-
visitors_number = visitors.get_number_of_visitors(language)
32-
completion_progress.append((language, completion_number, visitors_number))
31+
for language, repo in repositories.get_languages_and_repos():
32+
if repo:
33+
completion_number = get_completion(clones_dir, repo)
34+
visitors_number = visitors.get_number_of_visitors(language)
35+
else:
36+
completion_number, branch, visitors_number = 0., "", 0
37+
completion_progress.append((language, repo, completion_number, visitors_number))
3338
print(completion_progress[-1])
3439

3540
template = Template("""
@@ -49,10 +54,11 @@
4954
</tr>
5055
</thead>
5156
<tbody>
52-
{% for language, completion, visitors in completion_progress | sort(attribute=1) | reverse %}
57+
{% for language, repo, completion, visitors in completion_progress | sort(attribute=2) | reverse %}
5358
<tr>
59+
{% if repo %}
5460
<td data-label="language">
55-
<a href="https://github.com/python/python-docs-{{ language }}" target="_blank">
61+
<a href="https://github.com/{{ repo }}" target="_blank">
5662
{{ language }}
5763
</a>
5864
</td>
@@ -61,6 +67,10 @@
6167
{{ '{:,}'.format(visitors) }}
6268
</a>
6369
</td>
70+
{% else %}
71+
<td data-label="language">{{ language }}</td>
72+
<td data-label="visitors">0</td>
73+
{% endif %}
6474
<td data-label="completion">
6575
<div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div>
6676
</td>

repositories.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import tempfile
2+
import pathlib
3+
import re
4+
from typing import Generator, Optional
5+
6+
import git
7+
from docutils import core
8+
from docutils.nodes import table, row
9+
10+
def get_languages_and_repos() -> Generator[tuple[str, Optional[str]], None, None]:
11+
with tempfile.TemporaryDirectory() as clone_path:
12+
git.Repo.clone_from(f'https://github.com/python/devguide.git', clone_path, depth=1)
13+
translating = pathlib.Path(clone_path, 'documentation/translating.rst').read_text()
14+
doctree = core.publish_doctree(translating)
15+
16+
for node in doctree.traverse(table):
17+
for row_node in node.traverse(row)[1:]:
18+
language = row_node[0].astext()
19+
repo = row_node[2].astext()
20+
language_code = re.match(r'.* \((.*)\)', language).group(1).lower().replace('_', '-')
21+
repo_match = re.match(':github:`GitHub <(.*)>`', repo)
22+
yield language_code, repo_match and repo_match.group(1)

0 commit comments

Comments
 (0)