|
| 1 | +# /// script |
| 2 | +# dependencies = [ |
| 3 | +# "gitpython", |
| 4 | +# "potodo", |
| 5 | +# "jinja2", |
| 6 | +# ] |
| 7 | +# /// |
| 8 | +from pathlib import Path |
| 9 | +from shutil import rmtree |
| 10 | +from tempfile import TemporaryDirectory |
| 11 | +from git import Repo, GitCommandError |
| 12 | +from potodo.potodo import scan_path |
| 13 | +from jinja2 import Template |
| 14 | + |
| 15 | +completion_progress = [] |
| 16 | + |
| 17 | +with TemporaryDirectory() as tmpdir: |
| 18 | + for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'): |
| 19 | + clone_path = Path(tmpdir, language) |
| 20 | + for branch in ('3.13', '3.12', '3.11', '3.10', '3.9'): |
| 21 | + try: |
| 22 | + Repo. clone_from( f'[email protected]:python/python-docs-{language}.git', clone_path, depth=1, branch=branch) |
| 23 | + except GitCommandError as e: |
| 24 | + print(f'failed to clone {language} {branch}') |
| 25 | + continue |
| 26 | + try: |
| 27 | + completion = scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion |
| 28 | + except OSError: |
| 29 | + print(f'failed to scan {language} {branch}') |
| 30 | + rmtree(clone_path) |
| 31 | + continue |
| 32 | + else: |
| 33 | + break |
| 34 | + completion_progress.append((language, completion, branch)) |
| 35 | + print(completion_progress[-1]) |
| 36 | + |
| 37 | +template = Template(""" |
| 38 | +<html lang="en"> |
| 39 | +<body> |
| 40 | +<table> |
| 41 | +<tr><th>language</th><th>completion</th><th>branch</th></tr> |
| 42 | +{% for language, completion, branch in completion_progress | sort(attribute=1) | reverse %} |
| 43 | +<tr><td>{{ language }}</td><td>{{ completion | round(2) }}</td><td>{{ branch }}</td></tr> |
| 44 | +{% endfor %} |
| 45 | +</table> |
| 46 | +</body> |
| 47 | +</html> |
| 48 | +""") |
| 49 | + |
| 50 | +output = template.render(completion_progress=completion_progress) |
| 51 | + |
| 52 | +with open("index.html", "w") as file: |
| 53 | + file.write(output) |
0 commit comments