diff --git a/completion.py b/completion.py index e8484e34e..9cbb21392 100644 --- a/completion.py +++ b/completion.py @@ -23,14 +23,20 @@ def get_completion(clones_dir: str, repo: str) -> tuple[float, str, float]: clone_path = Path(clones_dir, 'translations', repo) for branch in branches_from_peps() + ['master', 'main']: try: - clone_repo = git.Repo.clone_from( - f'https://github.com/{repo}.git', clone_path, branch=branch - ) + if not clone_path.exists(): + clone_repo = git.Repo.clone_from( + f'https://github.com/{repo}.git', clone_path, branch=branch + ) + else: + (clone_repo := git.Repo(clone_path)).git.fetch() + clone_repo.git.switch(branch) + clone_repo.git.pull() except git.GitCommandError: - print(f'failed to clone {repo} {branch}') + print(f'failure: {branch} {repo}: clone or switch, continuing') branch = '' continue else: + print(f'success: {branch} {repo}: clone or switch') break path_for_merge = Path(clones_dir, 'rebased_translations', repo) completion = potodo.merge_and_scan_paths( diff --git a/generate.py b/generate.py index 2a8292b56..88d05e8ad 100644 --- a/generate.py +++ b/generate.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import json import concurrent.futures import itertools @@ -20,20 +22,26 @@ generation_time = datetime.now(timezone.utc) -def get_completion_progress() -> Iterator['LanguageProjectData']: +def get_completion_progress() -> Iterator[LanguageProjectData]: clones_dir = Path('clones') - Repo.clone_from( - 'https://github.com/python/devguide.git', - devguide_dir := Path(clones_dir, 'devguide'), - depth=1, - ) + if not (devguide_dir := Path(clones_dir, 'devguide')).exists(): + Repo.clone_from('https://github.com/python/devguide.git', devguide_dir, depth=1) + else: + Repo(devguide_dir).git.pull() latest_branch = branches_from_peps()[0] - Repo.clone_from( - 'https://github.com/python/cpython.git', - cpython_dir := Path(clones_dir, 'cpython'), - depth=1, - branch=latest_branch, - ) + if not (cpython_dir := Path(clones_dir, 'cpython')).exists(): + Repo.clone_from( + 'https://github.com/python/cpython.git', + cpython_dir, + depth=1, + branch=latest_branch, + ) + else: + (cpython_repo := Repo(cpython_dir)).git.fetch() + cpython_repo.git.switch(latest_branch) + cpython_repo.git.pull() + + subprocess.run(['make', '-C', cpython_dir / 'Doc', 'clean'], check=True) subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True) subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True) @@ -56,7 +64,7 @@ def get_project_data( repo: str | None, languages_built: dict[str, str], clones_dir: str, -) -> 'LanguageProjectData': +) -> LanguageProjectData: built = language.code in languages_built if repo: completion, branch, change = get_completion(clones_dir, repo)