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
13 changes: 8 additions & 5 deletions completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import git
from potodo import potodo

import translators


@cache
def branches_from_devguide(devguide_dir: Path) -> list[str]:
p = devguide_dir.joinpath('include/release-cycle.json')
Expand All @@ -15,20 +18,20 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
]


def get_completion(clones_dir: str, repo: str) -> float:
def get_completion(clones_dir: str, repo: str) -> tuple[float, int]:
clone_path = Path(clones_dir, repo)
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']:
try:
git.Repo.clone_from(
f'https://github.com/{repo}.git', clone_path, depth=1, branch=branch
)
git.Repo.clone_from(f'https://github.com/{repo}.git', clone_path, branch=branch)
except git.GitCommandError:
print(f'failed to clone {repo} {branch}')
translators_number = 0
continue
else:
translators_number = translators.get_number(clone_path)
break
with TemporaryDirectory() as tmpdir:
completion = potodo.merge_and_scan_path(
clone_path, pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'), merge_path=Path(tmpdir), hide_reserved=False, api_url=''
).completion
return completion
return completion, translators_number
9 changes: 6 additions & 3 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
for language, repo in repositories.get_languages_and_repos(devguide_dir):
if repo:
completion_number = get_completion(clones_dir, 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, visitors_number))
completion_progress.append((language, repo, completion_number, translators_number, visitors_number))
print(completion_progress[-1])

template = Template(
Expand All @@ -53,11 +53,12 @@
<tr>
<th>language</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, visitors in completion_progress | sort(attribute=2) | reverse %}
{% for language, repo, completion, translators, visitors in completion_progress | sort(attribute=2) | reverse %}
<tr>
{% if repo %}
<td data-label="language">
Expand All @@ -70,9 +71,11 @@
{{ '{:,}'.format(visitors) }}
</a>
</td>
<td data-label="translators">{{ '{:,}'.format(translators) }}</td>
{% else %}
<td data-label="language">{{ language }}</td>
<td data-label="visitors">0</td>
<td data-label="translators">0</td>
{% endif %}
<td data-label="completion">
<div class="progress-bar" style="width: {{ completion | round(2) }}%;">{{ completion | round(2) }}%</div>
Expand Down
30 changes: 30 additions & 0 deletions translators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from collections.abc import Generator
from pathlib import Path

from git import Repo
from polib import pofile


def get_number(path: Path) -> int:
from_headers = len(set(yield_from_headers(path)))
from_git_history = get_number_from_git_history(path)
return max(from_headers, from_git_history)

def get_number_from_git_history(path: Path) -> int:
return len(Repo(path).git.shortlog('-s', 'HEAD').splitlines())

def yield_from_headers(path: Path) -> Generator[str, None, None]:
for file in path.rglob('*.po'):
try:
header = pofile(file).header.splitlines()
except IOError:
continue
if 'Translators:' not in header:
continue
for translator_record in header[header.index('Translators:') + 1:]:
try:
translator, _year = translator_record.split(', ')
except ValueError:
yield translator_record
else:
yield translator
Loading