Skip to content

Commit 39b29ac

Browse files
committed
Get rid of cloning in generate_metadata.py
1 parent 6bc1d2a commit 39b29ac

File tree

3 files changed

+13
-42
lines changed

3 files changed

+13
-42
lines changed

build_warnings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def number(clones_dir: str, repo: str, language_code: str) -> int:
1212
else:
1313
lang_with_locale = language_part
1414
locale_dir = Path(clones_dir, f'cpython/Doc/locales/{lang_with_locale}/LC_MESSAGES')
15-
locale_dir.mkdir(parents=True)
16-
for po_file in Path(clones_dir, repo).rglob('*.po'):
17-
relative_path = po_file.relative_to(Path(clones_dir, repo))
15+
locale_dir.mkdir(parents=True, exist_ok=True)
16+
for po_file in (repo_dir := Path(clones_dir, 'translations', repo)).rglob('*.po'):
17+
relative_path = po_file.relative_to(repo_dir)
1818
target_file = locale_dir / relative_path
1919
target_file.parent.mkdir(parents=True, exist_ok=True)
2020
copyfile(po_file, target_file)

generate_metadata.py

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,18 @@
1313
import concurrent.futures
1414
import itertools
1515
import logging
16-
import subprocess
1716
from collections.abc import Iterator, Sequence
1817
from datetime import datetime, timezone
1918
from json import loads
2019
from pathlib import Path
2120
from sys import argv
22-
from tempfile import TemporaryDirectory
2321

2422
import dacite
25-
import git
26-
from git import Repo
2723
from jinja2 import Template
2824
from urllib3 import request
2925

3026
import build_warnings
3127
import sphinx_lint
32-
from completion import branches_from_devguide
3328
from generate import LanguageProjectData
3429
from repositories import Language
3530

@@ -39,41 +34,17 @@
3934
def get_projects_metadata(
4035
completion_progress: Sequence[LanguageProjectData],
4136
) -> Iterator[tuple[int, int]]:
42-
with TemporaryDirectory() as clones_dir:
43-
Repo.clone_from(
44-
'https://github.com/python/devguide.git',
45-
devguide_dir := Path(clones_dir, 'devguide'),
46-
depth=1,
37+
with concurrent.futures.ProcessPoolExecutor() as executor:
38+
return executor.map(
39+
get_metadata,
40+
*zip(*map(get_language_repo_and_completion, completion_progress)),
41+
itertools.repeat(Path('clones')),
4742
)
48-
latest_branch = branches_from_devguide(devguide_dir)[0]
49-
Repo.clone_from(
50-
'https://github.com/python/cpython.git',
51-
cpython_dir := Path(clones_dir, 'cpython'),
52-
depth=1,
53-
branch=latest_branch,
54-
)
55-
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
56-
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
57-
with concurrent.futures.ProcessPoolExecutor() as executor:
58-
return executor.map(
59-
get_metadata,
60-
*zip(
61-
*map(get_language_repo_branch_and_completion, completion_progress)
62-
),
63-
itertools.repeat(clones_dir),
64-
)
6543

6644

6745
def get_metadata(
68-
language: Language,
69-
repo: str | None,
70-
branch: str | None,
71-
completion: float,
72-
clones_dir: str,
46+
language: Language, repo: str | None, completion: float, clones_dir: str
7347
) -> tuple[int, int]:
74-
if repo:
75-
clone_path = Path(clones_dir, repo)
76-
git.Repo.clone_from(f'https://github.com/{repo}.git', clone_path, branch=branch)
7748
return (
7849
repo
7950
and completion
@@ -84,10 +55,10 @@ def get_metadata(
8455
) or (0, 0)
8556

8657

87-
def get_language_repo_branch_and_completion(
58+
def get_language_repo_and_completion(
8859
project: LanguageProjectData,
89-
) -> tuple[Language, str | None, str | None, float]:
90-
return project.language, project.repository, project.branch, project.completion
60+
) -> tuple[Language, str | None, float]:
61+
return project.language, project.repository, project.completion
9162

9263

9364
if __name__ == '__main__':

sphinx_lint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ def store_and_count_failures(clones_dir: str, repo: str, language_code: str) ->
1414

1515
def yield_failures(clones_dir: str, repo: str) -> Iterator[str]:
1616
enabled_checkers = [c for c in checkers.all_checkers.values() if c.enabled]
17-
for path in Path(clones_dir, repo).rglob('*.po'):
17+
for path in Path(clones_dir, 'translations', repo).rglob('*.po'):
1818
yield check_file(path.as_posix(), enabled_checkers)

0 commit comments

Comments
 (0)