Skip to content

Commit e44b0ff

Browse files
Merge branch 'main' into build-warnings-new-tab
# Conflicts: # completion.py # template.html.jinja
2 parents b391889 + 8a0c1a5 commit e44b0ff

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

.github/workflows/update.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
git-config-name: github-actions[bot]
3131
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
3232
- name: Deploy to subdirectory if pull request 🚀
33-
if: github.event_name == 'pull_request'
33+
# This does not work for PRs from forks
34+
if: github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
3435
uses: JamesIves/github-pages-deploy-action@v4
3536
with:
3637
folder: build
@@ -39,7 +40,8 @@ jobs:
3940
git-config-name: github-actions[bot]
4041
git-config-email: 41898282+github-actions[bot]@users.noreply.github.com
4142
- name: Update PR description if pull request
42-
if: github.event_name == 'pull_request'
43+
# This does not work for PRs from forks
44+
if: github.event_name == 'pull_request' && !github.event.pull_request.head.repo.fork
4345
uses: chabroA/[email protected]
4446
with:
4547
auth: ${{ secrets.GITHUB_TOKEN }}

completion.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def branches_from_devguide(devguide_dir: Path) -> list[str]:
2222

2323
def get_completion(
2424
clones_dir: str, repo: str
25-
) -> tuple[float, 'TranslatorsData', str | None]:
25+
) -> tuple[float, 'TranslatorsData', str, float]:
2626
clone_path = Path(clones_dir, repo)
2727
for branch in branches_from_devguide(Path(clones_dir, 'devguide')) + [
2828
'master',
2929
'main',
3030
]:
3131
try:
32-
git.Repo.clone_from(
32+
clone_repo = git.Repo.clone_from(
3333
f'https://github.com/{repo}.git', clone_path, branch=branch
3434
)
3535
except git.GitCommandError:
@@ -50,7 +50,27 @@ def get_completion(
5050
hide_reserved=False,
5151
api_url='',
5252
).completion
53-
return completion, translators_data, branch or None
53+
54+
if completion:
55+
# Fetch commit from before 30 days ago and checkout
56+
commit = next(
57+
clone_repo.iter_commits('HEAD', max_count=1, before='30 days ago')
58+
)
59+
clone_repo.git.checkout(commit.hexsha)
60+
with TemporaryDirectory() as tmpdir:
61+
month_ago_completion = potodo.merge_and_scan_path(
62+
clone_path,
63+
pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'),
64+
merge_path=Path(tmpdir),
65+
hide_reserved=False,
66+
api_url='',
67+
).completion
68+
else:
69+
month_ago_completion = 0.0
70+
71+
change = completion - month_ago_completion
72+
73+
return completion, translators_data, branch or None, change
5474

5575

5676
@dataclass(frozen=True)

generate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ def get_project_data(
6969
) -> 'LanguageProjectData':
7070
built = language.code in languages_built
7171
if repo:
72-
completion, translators_data, branch = get_completion(clones_dir, repo)
72+
completion, translators_data, branch, change = get_completion(clones_dir, repo)
7373
visitors_num = get_number_of_visitors(language.code, http) if built else 0
7474
else:
7575
completion = 0.0
7676
translators_data = TranslatorsData(0, False)
77+
change = 0.0
7778
visitors_num = 0
7879
branch = None
7980
return LanguageProjectData(
8081
language,
8182
repo,
8283
branch,
8384
completion,
85+
change,
8486
translators_data,
8587
visitors_num,
8688
built,
@@ -96,6 +98,7 @@ class LanguageProjectData:
9698
repository: str | None
9799
branch: str | None
98100
completion: float
101+
change: float
99102
translators: TranslatorsData
100103
visitors: int
101104
built: bool

template.html.jinja

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<title>Python Docs Translation Dashboard</title>
44
<link rel="stylesheet" href="style.css">
55
<meta charset="UTF-8">
6+
<meta name="description" content="Python Docs Translation Dashboard">
67
<base target="_blank">
78
</head>
89
<body>
@@ -12,8 +13,7 @@
1213
<thead>
1314
<tr>
1415
<th>language</th>
15-
<th>contribute</th>
16-
<th>build</th>
16+
<th>switcher</th>
1717
<th>visitors*</th>
1818
<th>translators</th>
1919
<th>completion</th>
@@ -22,17 +22,14 @@
2222
<tbody>
2323
{% for project in completion_progress | sort(attribute='completion,translators.number') | reverse %}
2424
<tr>
25-
<td data-label="language">{{ project.language.name }} ({{ project.language.code }})</td>
26-
<td data-label="contribute">
27-
{% if project.contribution_link %}<a href="{{ project.contribution_link }}">{% endif %}
28-
{% if project.uses_platform %}platform{% else %}repository{% endif %}
29-
{% if project.contribution_link %}</a>{% endif %}
25+
<td data-label="language">
26+
<a href="{{ project.contribution_link }}" target="_blank">{{ project.language.name }} ({{ project.language.code }})</a>
3027
</td>
3128
<td data-label="build">
32-
{% if project.built %}
33-
<a href="https://docs.python.org/{{ project.language.code }}/">✓{% if project.in_switcher %} in switcher{% endif %}</a>
34-
{% else %}
35-
29+
{% if project.in_switcher %}
30+
<a href="https://docs.python.org/{{ project.language.code }}/" target="_blank">✓</a>
31+
{% elif project.built %}
32+
<a href="https://docs.python.org/{{ project.language.code }}/" target="_blank">✗</a>
3633
{% endif %}
3734
</td>
3835
<td data-label="visitors">

visitors.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
import io
33
import urllib.parse
44
import zipfile
5+
from logging import info
56

6-
from urllib3 import PoolManager
7+
from urllib3 import PoolManager, Retry
78

89

910
def get_number_of_visitors(language: str, http: PoolManager) -> int:
1011
params = urllib.parse.urlencode(
1112
{'filters': f'[["contains","event:page",["/{language}/"]]]', 'period': 'all'}
1213
)
13-
r = http.request('GET', f'https://plausible.io/docs.python.org/export?{params}')
14+
response = http.request(
15+
'GET',
16+
f'https://plausible.io/docs.python.org/export?{params}',
17+
retries=Retry(status_forcelist=(500,502)),
18+
)
19+
info(f'visitors {response.status=} ({language=})')
1420
with (
15-
zipfile.ZipFile(io.BytesIO(r.data), 'r') as z,
21+
zipfile.ZipFile(io.BytesIO(response.data), 'r') as z,
1622
z.open('visitors.csv') as csv_file,
1723
):
1824
csv_reader = csv.DictReader(io.TextIOWrapper(csv_file))

0 commit comments

Comments
 (0)