|
1 | 1 | import json |
2 | | -from collections.abc import Iterator |
3 | 2 | from dataclasses import dataclass |
4 | 3 | from functools import cache |
5 | 4 | from pathlib import Path |
|
13 | 12 |
|
14 | 13 |
|
15 | 14 | @cache |
16 | | -def latest_branch_from_devguide(devguide_dir: Path) -> str: |
| 15 | +def branches_from_devguide(devguide_dir: Path) -> list[str]: |
17 | 16 | p = devguide_dir.joinpath('include/release-cycle.json') |
18 | | - for branch in (data := json.loads(p.read_text())): |
19 | | - if data[branch]['status'] in ('bugfix', 'security'): |
20 | | - return branch |
21 | | - raise ValueError(f'Supported release not found in {p}') |
22 | | - |
23 | | - |
24 | | -def iterate_branches(latest: str) -> Iterator[str]: |
25 | | - yield latest |
26 | | - major, minor = latest.split('.') |
27 | | - while int(minor) > 6: # hu has 3.6 branch, hi has 3.7 |
28 | | - minor = str(int(minor) - 1) |
29 | | - yield f'{major}.{minor}' |
30 | | - yield 'master' |
| 17 | + data = json.loads(p.read_text()) |
| 18 | + return [ |
| 19 | + branch for branch in data if data[branch]['status'] in ('bugfix', 'security') |
| 20 | + ] |
31 | 21 |
|
32 | 22 |
|
33 | 23 | def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData']: |
34 | 24 | clone_path = Path(clones_dir, repo) |
35 | | - for branch in iterate_branches( |
36 | | - latest_branch_from_devguide(Path(clones_dir, 'devguide')) |
37 | | - ): |
| 25 | + for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']: |
38 | 26 | try: |
39 | 27 | git.Repo.clone_from( |
40 | 28 | f'https://github.com/{repo}.git', clone_path, branch=branch |
@@ -63,8 +51,3 @@ def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData' |
63 | 51 | class TranslatorsData: |
64 | 52 | number: int |
65 | 53 | link: str | Literal[False] |
66 | | - |
67 | | - |
68 | | -if __name__ == '__main__': |
69 | | - for branch in iterate_branches('3.13'): |
70 | | - print(branch) |
0 commit comments