diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index efc01349e..2e7a0e9db 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -17,6 +17,7 @@ jobs: python-version: "3.x" - uses: astral-sh/setup-uv@v4 - uses: actions/checkout@v4 + - run: sudo apt-get install -y gettext - run: uv run generate.py # generates "index.html" - run: mkdir -p build && cp index.html style.css build - name: Deploy 🚀 diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 7d3909c07..59be58c86 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,10 +8,17 @@ build: os: ubuntu-24.04 tools: python: "3" - commands: - - asdf plugin add uv - - asdf install uv latest - - asdf global uv latest - - uv run generate.py - - mkdir -p _readthedocs/html - - mv index.html style.css _readthedocs/html + apt_packages: + - gettext + jobs: + post_checkout: [] + install: + - asdf plugin add uv + - asdf install uv latest + pre_build: + - asdf global uv latest + build: + html: + - uv run generate.py + - mkdir -p _readthedocs/html + - mv index.html style.css _readthedocs/html diff --git a/completion.py b/completion.py index 1d9105db1..2869b5d02 100644 --- a/completion.py +++ b/completion.py @@ -1,11 +1,12 @@ -import pathlib -import shutil +from functools import cache +from pathlib import Path +from tempfile import TemporaryDirectory import git from potodo import potodo import requests - +@cache def branches_from_devguide() -> list[str]: r = requests.get( "https://raw.githubusercontent.com/" @@ -18,21 +19,21 @@ def branches_from_devguide() -> list[str]: ] -def get_completion_and_branch(tmpdir: str, language: str) -> tuple[float, str]: - clone_path = pathlib.Path(tmpdir, language) +def get_completion(clones_dir: str, language: str) -> float: + clone_path = Path(clones_dir, language) for branch in branches_from_devguide(): try: - git.Repo.clone_from(f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch) + git.Repo.clone_from( + f'https://github.com/python/python-docs-{language}.git', clone_path, depth=1, branch=branch + ) except git.GitCommandError: print(f'failed to clone {language} {branch}') continue - try: - completion = potodo.scan_path(clone_path, no_cache=True, hide_reserved=False, api_url='').completion - except OSError: - print(f'failed to scan {language} {branch}') - shutil.rmtree(clone_path) - continue else: break - return completion, branch + 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 diff --git a/generate.py b/generate.py index 690306d13..de64fa3d1 100644 --- a/generate.py +++ b/generate.py @@ -6,29 +6,37 @@ # "requests", # ] # /// +import subprocess from datetime import datetime, timezone +from pathlib import Path from tempfile import TemporaryDirectory +from git import Repo from jinja2 import Template -import completion import visitors +from completion import branches_from_devguide, get_completion completion_progress = [] generation_time = datetime.now(timezone.utc) -with TemporaryDirectory() as tmpdir: +with TemporaryDirectory() as clones_dir: + Repo.clone_from( + f'https://github.com/python/cpython.git', Path(clones_dir, 'cpython'), depth=1, branch=branches_from_devguide()[0] + ) + subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True) + subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True) for language in ('es', 'fr', 'id', 'it', 'ja', 'ko', 'pl', 'pt-br', 'tr', 'uk', 'zh-cn', 'zh-tw'): - completion_number, branch = completion.get_completion_and_branch(tmpdir, language) + completion_number = get_completion(clones_dir, language) visitors_number = visitors.get_number_of_visitors(language) - completion_progress.append((language, completion_number, branch, visitors_number)) + completion_progress.append((language, completion_number, visitors_number)) print(completion_progress[-1]) template = Template("""
-Last updated at {{ generation_time.strftime('%A, %d %B %Y, %X %Z') }}.
-Note that the completion value is based on files available in language Git repository and may not include e.g. resources which translation hasn't yet started.
""")