Skip to content

Commit 3e15d03

Browse files
authored
Use detected branches in contribution links (#211)
* Use detected branches in contribution links * simplify testing links * simplify testing links cases
1 parent d1211f9 commit 3e15d03

3 files changed

Lines changed: 48 additions & 36 deletions

File tree

‎contribute.py‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
custom_contributing_links: dict[str, str] = {
99
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
1010
'ko': 'https://www.flowdas.com/pages/python-docs-ko.html',
11-
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/3.14/README.rst#id2',
12-
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/3.14/CONTRIBUTING.rst',
13-
'id': 'https://github.com/python/python-docs-id/blob/3.14/README.md#berkontribusi-untuk-menerjemahkan',
14-
'tr': 'https://github.com/python/python-docs-tr/blob/3.12/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
15-
'el': 'https://github.com/python/python-docs-el/blob/3.14/CONTRIBUTING.md',
11+
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/{branch}/README.rst#id2',
12+
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/{branch}/CONTRIBUTING.rst',
13+
'id': 'https://github.com/python/python-docs-id/blob/{branch}/README.md#berkontribusi-untuk-menerjemahkan',
14+
'tr': 'https://github.com/python/python-docs-tr/blob/{branch}/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
15+
'el': 'https://github.com/python/python-docs-el/blob/{branch}/CONTRIBUTING.md',
1616
'pt-br': 'https://python.org.br/traducao/',
1717
}
1818

1919

20-
def get_contrib_link(language: str, repo: str | None) -> str | None:
20+
def get_contrib_link(language: str, repo: str | None, branch: str) -> str | None:
21+
if link := custom_contributing_links.get(language):
22+
return link.format(branch=branch)
23+
2124
return (
22-
custom_contributing_links.get(language)
23-
or (
25+
(
2426
language in pulling_from_transifex
2527
and 'https://explore.transifex.com/python-doc/python-newest/'
2628
)

‎generate.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_project_data(
8888
translated_name=languages_built.get(language.code)
8989
or translated_names.babel_autonym(language.code)
9090
or '',
91-
contribution_link=contribute.get_contrib_link(language.code, repo),
91+
contribution_link=contribute.get_contrib_link(language.code, repo, branch),
9292
)
9393

9494

‎tests/test_contribute.py‎

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,52 @@
99

1010
class testContributeLink(unittest.TestCase):
1111
def test_get_contrib_link(self):
12-
PULL_FROM_TX = 'https://explore.transifex.com/python-doc/python-newest/'
13-
DEVGUIDE = 'https://devguide.python.org/documentation/translations/translating/'
14-
1512
for code, repo, expected in (
16-
('en', None, DEVGUIDE),
17-
('pl', None, PULL_FROM_TX),
18-
('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'),
19-
(
20-
'zh-tw',
21-
None,
22-
'https://github.com/python/python-docs-zh-tw/blob/3.14/README.rst#id2',
23-
),
2413
(
25-
'id',
14+
'en',
2615
None,
27-
'https://github.com/python/python-docs-id/blob/3.14/README.md#berkontribusi-untuk-menerjemahkan',
16+
'https://devguide.python.org/documentation/translations/translating/',
2817
),
18+
('pl', None, 'https://explore.transifex.com/python-doc/python-newest/'),
19+
('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'),
2920
):
30-
with self.subTest(code=code, repo=repo, expected=expected):
31-
self.assertEqual(contribute.get_contrib_link(code, repo), expected)
21+
for branch in ('3.12', '3.14', '3.15', 'main', 'master'):
22+
with self.subTest(code=code, repo=repo, branch=branch):
23+
self.assertEqual(
24+
contribute.get_contrib_link(code, repo, branch), expected
25+
)
26+
27+
def test_custom_contrib_links(self):
28+
expected_links = {
29+
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/{branch}/README.rst#id2',
30+
'id': 'https://github.com/python/python-docs-id/blob/{branch}/README.md#berkontribusi-untuk-menerjemahkan',
31+
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/{branch}/CONTRIBUTING.rst',
32+
'tr': 'https://github.com/python/python-docs-tr/blob/{branch}/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
33+
'el': 'https://github.com/python/python-docs-el/blob/{branch}/CONTRIBUTING.md',
34+
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
35+
}
36+
for code, expected in expected_links.items():
37+
for branch in ('3.12', '3.14', '3.15', 'main', 'master'):
38+
with self.subTest(code=code, branch=branch):
39+
self.assertEqual(
40+
contribute.get_contrib_link(code, None, branch),
41+
expected.format(branch=branch),
42+
)
3243

3344
def test_links_are_valid(self):
34-
http = urllib3.PoolManager()
45+
http = urllib3.PoolManager(
46+
timeout=1.0, retries=urllib3.Retry(total=3, read=False)
47+
)
3548
for lang, link in contribute.custom_contributing_links.items():
36-
with self.subTest(lang=lang):
49+
link = link.format(branch='3.12' if lang == 'tr' else '3.14')
50+
with self.subTest(lang=lang, link=link):
3751
try:
38-
r = http.request('HEAD', link, timeout=urllib3.Timeout(10.0))
39-
self.assertTrue(
40-
200 <= r.status < 400, f'{link} returned {r.status}'
41-
)
42-
except urllib3.exceptions.MaxRetryError as e:
43-
if isinstance(e.reason, urllib3.exceptions.ReadTimeoutError):
44-
self.skipTest(f'{link}: read timeout, skipping slow server')
45-
self.fail(f'{link}: {e}')
46-
except urllib3.exceptions.HTTPError as e:
47-
self.fail(f'{link}: {e}')
52+
response = http.request('HEAD', link)
53+
except urllib3.exceptions.ReadTimeoutError:
54+
self.skipTest(f'{link}: read timeout, skipping slow server')
55+
self.assertTrue(
56+
200 <= response.status < 400, f'{link} returned {response.status}'
57+
)
4858

4959

5060
if __name__ == '__main__':

0 commit comments

Comments
 (0)