diff --git a/completion.py b/completion.py index cb5c7ca9e..ab9c36df1 100644 --- a/completion.py +++ b/completion.py @@ -1,15 +1,11 @@ import json -from dataclasses import dataclass from functools import cache from pathlib import Path from tempfile import TemporaryDirectory -from typing import Literal import git from potodo import potodo -import translators - @cache def branches_from_devguide(devguide_dir: Path) -> list[str]: @@ -22,9 +18,7 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]: ] -def get_completion( - clones_dir: str, repo: str -) -> tuple[float, 'TranslatorsData', str, float]: +def get_completion(clones_dir: str, repo: str) -> tuple[float, str, float]: clone_path = Path(clones_dir, 'translations', repo) for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + [ 'master', @@ -36,13 +30,9 @@ def get_completion( ) except git.GitCommandError: print(f'failed to clone {repo} {branch}') - translators_data = TranslatorsData(0, False) branch = '' continue else: - translators_number = translators.get_number(clone_path) - translators_link = translators.get_link(clone_path, repo, branch) - translators_data = TranslatorsData(translators_number, translators_link) break path_for_merge = Path(clones_dir, 'rebased_translations', repo) completion = potodo.merge_and_scan_path( @@ -77,10 +67,4 @@ def get_completion( change = completion - month_ago_completion - return completion, translators_data, branch, change - - -@dataclass(frozen=True) -class TranslatorsData: - number: int - link: str | Literal[False] + return completion, branch, change diff --git a/generate.py b/generate.py index 2998dd2de..9b162125e 100644 --- a/generate.py +++ b/generate.py @@ -14,7 +14,7 @@ import build_status import contribute -from completion import branches_from_devguide, get_completion, TranslatorsData +from completion import branches_from_devguide, get_completion from repositories import Language, get_languages_and_repos generation_time = datetime.now(timezone.utc) @@ -59,10 +59,9 @@ def get_project_data( ) -> 'LanguageProjectData': built = language.code in languages_built if repo: - completion, translators_data, branch, change = get_completion(clones_dir, repo) + completion, branch, change = get_completion(clones_dir, repo) else: completion = 0.0 - translators_data = TranslatorsData(0, False) change = 0.0 branch = '' @@ -72,7 +71,6 @@ def get_project_data( branch, completion, change, - translators_data, built, translated_name=languages_built.get(language.code, ''), uses_platform=language.code in contribute.pulling_from_transifex, @@ -87,7 +85,6 @@ class LanguageProjectData: branch: str completion: float change: float - translators: TranslatorsData built: bool translated_name: str uses_platform: bool diff --git a/templates/index.html.jinja b/templates/index.html.jinja index 7e3987c8f..b36f7a8ff 100644 --- a/templates/index.html.jinja +++ b/templates/index.html.jinja @@ -3,7 +3,7 @@ {% block main %}
- {% for project in completion_progress | sort(attribute='completion,translators.number') | reverse %} + {% for project in completion_progress | sort(attribute='completion') | reverse %}
diff --git a/templates/metadata.html.jinja b/templates/metadata.html.jinja index 9633586ec..6e9064768 100644 --- a/templates/metadata.html.jinja +++ b/templates/metadata.html.jinja @@ -12,7 +12,7 @@ -{% for project, metadata in metadata | sort(attribute='0.completion,0.translators.number') | reverse %} +{% for project, metadata in metadata | sort(attribute='0.completion') | reverse %} {{ project.language.name }} ({{ project.language.code }}) {{ project.branch }} diff --git a/translators.py b/translators.py deleted file mode 100644 index aaae2399f..000000000 --- a/translators.py +++ /dev/null @@ -1,79 +0,0 @@ -from collections.abc import Iterator -from pathlib import Path -from re import fullmatch -from tempfile import TemporaryDirectory -from typing import Literal - -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) - from_translators_file = len(get_from_translators_file(path)) - return max(from_headers, from_git_history, from_translators_file) - - -def get_number_from_git_history(path: Path) -> int: - return len(Repo(path).git.shortlog('-s', 'HEAD').splitlines()) - - -def yield_from_headers(path: Path) -> Iterator[str]: - 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 - - -def get_from_translators_file(path: Path) -> list[str]: - if not (file := path.joinpath('TRANSLATORS')).exists(): - return [] - return list( - line - for line in file.read_text().splitlines() - if line != 'Translators' - and not fullmatch(r'-*', line) - and not line.startswith('# ') - ) - - -def get_link(clone_path: Path, repo: str, branch: str) -> str | Literal[False]: - return ( - clone_path.joinpath('TRANSLATORS').exists() - and f'https://github.com/{repo}/blob/{branch}/TRANSLATORS' - ) - - -if __name__ == '__main__': - for lang, branch in ( - ('es', '3.13'), - ('hu', '3.6'), - ('pl', '3.13'), - ('zh-tw', '3.13'), - ('id', '3.9'), - ('fr', '3.13'), - ('hu', '3.6'), - ): - with TemporaryDirectory() as directory: - Repo.clone_from( - f'https://github.com/python/python-docs-{lang}', - directory, - branch=branch, - ) - from_headers = len(set(yield_from_headers(path := Path(directory)))) - from_git_history = get_number_from_git_history(path) - from_translators_file = len(get_from_translators_file(path)) - print( - f'{lang}: {from_headers=}, {from_git_history=}, {from_translators_file=}' - )