-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcompletion.py
More file actions
90 lines (82 loc) · 3.14 KB
/
completion.py
File metadata and controls
90 lines (82 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import json
from functools import cache
from pathlib import Path
from tempfile import TemporaryDirectory
import git
import urllib3
from potodo import potodo
from potodo.arguments_handling import Filters
@cache
def branches_from_peps() -> list[str]:
resp = urllib3.request('GET', 'https://peps.python.org/api/release-cycle.json')
data = json.loads(resp.data)
return [
branch
for branch, metadata in data.items()
if metadata['status'] in ('prerelease', 'bugfix', 'security')
]
def get_completion(
clones_dir: str, repo: str
) -> tuple[float, float, str, float, float]:
clone_path = Path(clones_dir, 'translations', repo)
for branch in branches_from_peps() + ['master', 'main']:
try:
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'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)
project = potodo.merge_and_scan_paths(
[clone_path],
pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'),
merge_path=path_for_merge.absolute(),
api_url='',
)
completion = project.completion
core_excludes = ['**/*', '!bugs.po', '!tutorial/*', '!library/functions.po']
project.filter(
filters=Filters(False, True, 0, 100, False, False), exclude=core_excludes
)
core_completion = project.completion
if completion:
# Fetch commit from before 30 days ago and checkout
try:
commit = next(
clone_repo.iter_commits('HEAD', max_count=1, before='30 days ago')
)
except StopIteration:
month_ago_completion = 0.0
month_ago_core_completion = 0.0
else:
clone_repo.git.checkout(commit.hexsha)
with TemporaryDirectory() as tmpdir:
project = potodo.merge_and_scan_paths(
[clone_path],
pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'),
merge_path=Path(tmpdir),
api_url='',
)
month_ago_completion = project.completion
project.filter(
filters=Filters(False, True, 0, 100, False, False),
exclude=core_excludes,
)
month_ago_core_completion = project.completion
clone_repo.git.checkout(branch) # restore the original state
else:
month_ago_completion = 0.0
month_ago_core_completion = 0.0
change = completion - month_ago_completion
core_change = core_completion - month_ago_core_completion
return core_completion, completion, branch, core_change, change