Skip to content

Commit aa322d7

Browse files
committed
Fetch devguide once
1 parent f7f454f commit aa322d7

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

completion.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1+
import json
12
from functools import cache
23
from pathlib import Path
34
from tempfile import TemporaryDirectory
45

56
import git
67
from potodo import potodo
7-
import requests
88

99
@cache
10-
def branches_from_devguide() -> list[str]:
11-
r = requests.get(
12-
"https://raw.githubusercontent.com/"
13-
"python/devguide/main/include/release-cycle.json",
14-
timeout=10,
15-
)
16-
data = r.json()
10+
def branches_from_devguide(devguide_dir: Path) -> list[str]:
11+
p = devguide_dir.joinpath('include/release-cycle.json')
12+
data = json.loads(p.read_text())
1713
return [
1814
branch for branch in data if data[branch]["status"] in ("bugfix", "security")
1915
]
2016

2117

2218
def get_completion(clones_dir: str, repo: str) -> float:
2319
clone_path = Path(clones_dir, repo)
24-
for branch in branches_from_devguide() + ['master']:
20+
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']:
2521
try:
2622
git.Repo.clone_from(
2723
f'https://github.com/{repo}.git', clone_path, depth=1, branch=branch

generate.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,24 @@
2323
generation_time = datetime.now(timezone.utc)
2424

2525
with TemporaryDirectory() as clones_dir:
26+
Repo.clone_from(f'https://github.com/python/devguide.git', devguide_dir := Path(clones_dir, 'devguide'), depth=1)
27+
latest_branch = branches_from_devguide(devguide_dir)[0]
2628
Repo.clone_from(
27-
f'https://github.com/python/cpython.git', Path(clones_dir, 'cpython'), depth=1, branch=branches_from_devguide()[0]
29+
f'https://github.com/python/cpython.git', Path(clones_dir, 'cpython'), depth=1, branch=latest_branch
2830
)
2931
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'venv'], check=True)
3032
subprocess.run(['make', '-C', Path(clones_dir, 'cpython/Doc'), 'gettext'], check=True)
31-
for language, repo in repositories.get_languages_and_repos():
33+
for language, repo in repositories.get_languages_and_repos(devguide_dir):
3234
if repo:
3335
completion_number = get_completion(clones_dir, repo)
3436
visitors_number = visitors.get_number_of_visitors(language)
3537
else:
36-
completion_number, visitors_number = 0., 0
38+
completion_number, visitors_number = 0.0, 0
3739
completion_progress.append((language, repo, completion_number, visitors_number))
3840
print(completion_progress[-1])
3941

40-
template = Template("""
42+
template = Template(
43+
"""
4144
<html lang="en">
4245
<head>
4346
<title>Python Docs Translation Dashboard</title>
@@ -81,7 +84,8 @@
8184
<p>Last updated at {{ generation_time.strftime('%A, %d %B %Y, %X %Z') }}.</p>
8285
</body>
8386
</html>
84-
""")
87+
"""
88+
)
8589

8690
output = template.render(completion_progress=completion_progress, generation_time=generation_time)
8791

repositories.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import re
44
from typing import Generator, Optional
55

6-
import git
76
from docutils import core
87
from docutils.nodes import table, row
98

10-
def get_languages_and_repos() -> Generator[tuple[str, Optional[str]], None, None]:
11-
with tempfile.TemporaryDirectory() as clone_path:
12-
git.Repo.clone_from(f'https://github.com/python/devguide.git', clone_path, depth=1)
13-
translating = pathlib.Path(clone_path, 'documentation/translating.rst').read_text()
9+
10+
def get_languages_and_repos(devguide_dir: pathlib.Path) -> Generator[tuple[str, Optional[str]], None, None]:
11+
translating = devguide_dir.joinpath('documentation/translating.rst').read_text()
1412
doctree = core.publish_doctree(translating)
1513

1614
for node in doctree.traverse(table):

0 commit comments

Comments
 (0)