Skip to content

Commit 03bf88d

Browse files
authored
Merge branch 'main' into build-warnings
2 parents f2fbac0 + c02c831 commit 03bf88d

File tree

4 files changed

+60
-14
lines changed

4 files changed

+60
-14
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on:
2+
pull_request:
3+
types:
4+
- closed
5+
jobs:
6+
cleanup:
7+
runs-on: ubuntu-latest
8+
permissions:
9+
contents: write
10+
steps:
11+
- uses: actions/checkout@v4
12+
with:
13+
ref: gh-pages
14+
- run: git config user.name "github-actions[bot]"
15+
- run: git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
16+
- run: git rm ${{ github.ref_name }}
17+
- run: git commit -m 'Cleaning up gh-pages after ${{ github.ref_name }}'
18+
- uses: ad-m/github-push-action@master

.github/workflows/update.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
permissions:
1313
contents: write
14+
pull-requests: write
1415
steps:
1516
- uses: actions/setup-python@v5
1617
with:
@@ -19,7 +20,7 @@ jobs:
1920
- uses: actions/checkout@v4
2021
- run: sudo apt-get install -y gettext
2122
- run: uv run generate.py # generates "index.html"
22-
- run: mkdir -p build && cp index.html style.css warnings* build
23+
- run: mkdir -p build && cp index.* style.css warnings* build
2324
- name: Deploy 🚀
2425
if: github.event_name != 'pull_request'
2526
uses: JamesIves/github-pages-deploy-action@v4
@@ -28,6 +29,25 @@ jobs:
2829
clean: false
2930
git-config-name: github-actions[bot]
3031
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
32+
- name: Deploy to subdirectory if pull request 🚀
33+
if: github.event_name == 'pull_request'
34+
uses: JamesIves/github-pages-deploy-action@v4
35+
with:
36+
folder: build
37+
target-folder: ${{ github.ref_name }}
38+
clean: false
39+
git-config-name: github-actions[bot]
40+
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
41+
- name: Update PR description if pull request
42+
if: github.event_name == 'pull_request'
43+
uses: chabroA/[email protected]
44+
with:
45+
auth: ${{ secrets.GITHUB_TOKEN }}
46+
repo: ${{ github.event.repository.name }}
47+
owner: ${{ github.repository_owner }}
48+
pr: ${{ github.event.number }}
49+
url: "https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${{ github.ref_name }}/"
50+
message: "📊 Dashboard preview 📊:"
3151
- name: Debug index.html if pull request
3252
if: github.event_name == 'pull_request'
3353
run: |

completion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
2020
]
2121

2222

23-
def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData']:
23+
def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData', str]:
2424
clone_path = Path(clones_dir, repo)
2525
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + ['master']:
2626
try:
@@ -44,7 +44,7 @@ def get_completion(clones_dir: str, repo: str) -> tuple[float, 'TranslatorsData'
4444
hide_reserved=False,
4545
api_url='',
4646
).completion
47-
return completion, translators_data
47+
return completion, translators_data, branch
4848

4949

5050
@dataclass(frozen=True)

generate.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
# "python-docs-theme",
1111
# ]
1212
# ///
13+
import json
14+
import concurrent.futures
15+
import itertools
1316
import logging
1417
import subprocess
1518
from collections.abc import Iterator
16-
from concurrent.futures import ProcessPoolExecutor
17-
from dataclasses import dataclass
19+
from dataclasses import dataclass, asdict
1820
from datetime import datetime, timezone
1921
from itertools import repeat
2022
from pathlib import Path
@@ -51,26 +53,26 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
5153
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
5254
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
5355
languages_built = dict(build_status.get_languages(http := PoolManager()))
54-
with ProcessPoolExecutor() as executor:
56+
with concurrent.futures.ProcessPoolExecutor() as executor:
5557
return executor.map(
56-
get_data,
58+
get_project_data,
5759
*zip(*get_languages_and_repos(devguide_dir)),
58-
repeat(languages_built),
59-
repeat(clones_dir),
60-
repeat(http),
60+
itertools.repeat(languages_built),
61+
itertools.repeat(clones_dir),
62+
itertools.repeat(http),
6163
)
6264

6365

64-
def get_data(
66+
def get_project_data(
6567
language: Language,
66-
repo: str,
68+
repo: str | None,
6769
languages_built: dict[str, bool],
6870
clones_dir: str,
6971
http: PoolManager,
7072
) -> 'LanguageProjectData':
7173
built = language.code in languages_built
7274
if repo:
73-
completion, translators_data = get_completion(clones_dir, repo)
75+
completion, translators_data, branch = get_completion(clones_dir, repo)
7476
visitors_num = get_number_of_visitors(language.code, http) if built else 0
7577
warnings = (
7678
build_warnings.number(clones_dir, repo, language.code) if completion else 0
@@ -80,9 +82,11 @@ def get_data(
8082
translators_data = TranslatorsData(0, False)
8183
visitors_num = 0
8284
warnings = 0
85+
branch = None
8386
return LanguageProjectData(
8487
language,
8588
repo,
89+
branch,
8690
completion,
8791
translators_data,
8892
visitors_num,
@@ -98,6 +102,7 @@ def get_data(
98102
class LanguageProjectData:
99103
language: Language
100104
repository: str | None
105+
branch: str | None
101106
completion: float
102107
translators: TranslatorsData
103108
visitors: int
@@ -114,9 +119,12 @@ class LanguageProjectData:
114119
template = Template(Path('template.html.jinja').read_text())
115120

116121
output = template.render(
117-
completion_progress=list(get_completion_progress()),
122+
completion_progress=(completion_progress := list(get_completion_progress())),
118123
generation_time=generation_time,
119124
duration=(datetime.now(timezone.utc) - generation_time).seconds,
120125
)
121126

122127
Path('index.html').write_text(output)
128+
Path('index.json').write_text(
129+
json.dumps(completion_progress, indent=2, default=asdict)
130+
)

0 commit comments

Comments
 (0)