Skip to content

Commit 2cf4326

Browse files
authored
Don't require empty clones directory (#153)
1 parent 300f454 commit 2cf4326

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

completion.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,20 @@ def get_completion(clones_dir: str, repo: str) -> tuple[float, str, float]:
2323
clone_path = Path(clones_dir, 'translations', repo)
2424
for branch in branches_from_peps() + ['master', 'main']:
2525
try:
26-
clone_repo = git.Repo.clone_from(
27-
f'https://github.com/{repo}.git', clone_path, branch=branch
28-
)
26+
if not clone_path.exists():
27+
clone_repo = git.Repo.clone_from(
28+
f'https://github.com/{repo}.git', clone_path, branch=branch
29+
)
30+
else:
31+
(clone_repo := git.Repo(clone_path)).git.fetch()
32+
clone_repo.git.switch(branch)
33+
clone_repo.git.pull()
2934
except git.GitCommandError:
30-
print(f'failed to clone {repo} {branch}')
35+
print(f'failure: {branch} {repo}: clone or switch, continuing')
3136
branch = ''
3237
continue
3338
else:
39+
print(f'success: {branch} {repo}: clone or switch')
3440
break
3541
path_for_merge = Path(clones_dir, 'rebased_translations', repo)
3642
completion = potodo.merge_and_scan_paths(

generate.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import json
24
import concurrent.futures
35
import itertools
@@ -20,20 +22,26 @@
2022
generation_time = datetime.now(timezone.utc)
2123

2224

23-
def get_completion_progress() -> Iterator['LanguageProjectData']:
25+
def get_completion_progress() -> Iterator[LanguageProjectData]:
2426
clones_dir = Path('clones')
25-
Repo.clone_from(
26-
'https://github.com/python/devguide.git',
27-
devguide_dir := Path(clones_dir, 'devguide'),
28-
depth=1,
29-
)
27+
if not (devguide_dir := Path(clones_dir, 'devguide')).exists():
28+
Repo.clone_from('https://github.com/python/devguide.git', devguide_dir, depth=1)
29+
else:
30+
Repo(devguide_dir).git.pull()
3031
latest_branch = branches_from_peps()[0]
31-
Repo.clone_from(
32-
'https://github.com/python/cpython.git',
33-
cpython_dir := Path(clones_dir, 'cpython'),
34-
depth=1,
35-
branch=latest_branch,
36-
)
32+
if not (cpython_dir := Path(clones_dir, 'cpython')).exists():
33+
Repo.clone_from(
34+
'https://github.com/python/cpython.git',
35+
cpython_dir,
36+
depth=1,
37+
branch=latest_branch,
38+
)
39+
else:
40+
(cpython_repo := Repo(cpython_dir)).git.fetch()
41+
cpython_repo.git.switch(latest_branch)
42+
cpython_repo.git.pull()
43+
44+
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'clean'], check=True)
3745
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
3846
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
3947

@@ -56,7 +64,7 @@ def get_project_data(
5664
repo: str | None,
5765
languages_built: dict[str, str],
5866
clones_dir: str,
59-
) -> 'LanguageProjectData':
67+
) -> LanguageProjectData:
6068
built = language.code in languages_built
6169
if repo:
6270
completion, branch, change = get_completion(clones_dir, repo)

0 commit comments

Comments
 (0)