Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions contribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@
custom_contributing_links: dict[str, str] = {
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
'ko': 'https://www.flowdas.com/pages/python-docs-ko.html',
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/3.14/README.rst#id2',
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/3.14/CONTRIBUTING.rst',
'id': 'https://github.com/python/python-docs-id/blob/3.14/README.md#berkontribusi-untuk-menerjemahkan',
'tr': 'https://github.com/python/python-docs-tr/blob/3.12/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
'el': 'https://github.com/python/python-docs-el/blob/3.14/CONTRIBUTING.md',
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/{branch}/README.rst#id2',
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/{branch}/CONTRIBUTING.rst',
'id': 'https://github.com/python/python-docs-id/blob/{branch}/README.md#berkontribusi-untuk-menerjemahkan',
'tr': 'https://github.com/python/python-docs-tr/blob/{branch}/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
'el': 'https://github.com/python/python-docs-el/blob/{branch}/CONTRIBUTING.md',
'pt-br': 'https://python.org.br/traducao/',
}


def get_contrib_link(language: str, repo: str | None) -> str | None:
def get_contrib_link(language: str, repo: str | None, branch: str) -> str | None:
if link := custom_contributing_links.get(language):
return link.format(branch=branch)

return (
custom_contributing_links.get(language)
or (
(
language in pulling_from_transifex
and 'https://explore.transifex.com/python-doc/python-newest/'
)
Expand Down
2 changes: 1 addition & 1 deletion generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_project_data(
translated_name=languages_built.get(language.code)
or translated_names.babel_autonym(language.code)
or '',
contribution_link=contribute.get_contrib_link(language.code, repo),
contribution_link=contribute.get_contrib_link(language.code, repo, branch),
)


Expand Down
64 changes: 37 additions & 27 deletions tests/test_contribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,52 @@

class testContributeLink(unittest.TestCase):
def test_get_contrib_link(self):
PULL_FROM_TX = 'https://explore.transifex.com/python-doc/python-newest/'
DEVGUIDE = 'https://devguide.python.org/documentation/translations/translating/'

for code, repo, expected in (
('en', None, DEVGUIDE),
('pl', None, PULL_FROM_TX),
('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'),
(
'zh-tw',
None,
'https://github.com/python/python-docs-zh-tw/blob/3.14/README.rst#id2',
),
(
'id',
'en',
None,
'https://github.com/python/python-docs-id/blob/3.14/README.md#berkontribusi-untuk-menerjemahkan',
'https://devguide.python.org/documentation/translations/translating/',
),
('pl', None, 'https://explore.transifex.com/python-doc/python-newest/'),
('ar', 'python/python-docs-ar', 'https://github.com/python/python-docs-ar'),
):
with self.subTest(code=code, repo=repo, expected=expected):
self.assertEqual(contribute.get_contrib_link(code, repo), expected)
for branch in ('3.12', '3.14', '3.15', 'main', 'master'):
with self.subTest(code=code, repo=repo, branch=branch):
self.assertEqual(
contribute.get_contrib_link(code, repo, branch), expected
)

def test_custom_contrib_links(self):
expected_links = {
'zh-tw': 'https://github.com/python/python-docs-zh-tw/blob/{branch}/README.rst#id2',
'id': 'https://github.com/python/python-docs-id/blob/{branch}/README.md#berkontribusi-untuk-menerjemahkan',
'fr': 'https://git.afpy.org/AFPy/python-docs-fr/src/branch/{branch}/CONTRIBUTING.rst',
'tr': 'https://github.com/python/python-docs-tr/blob/{branch}/README.md#%C3%A7eviriye-katk%C4%B1da-bulunmak',
'el': 'https://github.com/python/python-docs-el/blob/{branch}/CONTRIBUTING.md',
'es': 'https://python-docs-es.readthedocs.io/page/CONTRIBUTING.html',
}
for code, expected in expected_links.items():
for branch in ('3.12', '3.14', '3.15', 'main', 'master'):
with self.subTest(code=code, branch=branch):
self.assertEqual(
contribute.get_contrib_link(code, None, branch),
expected.format(branch=branch),
)

def test_links_are_valid(self):
http = urllib3.PoolManager()
http = urllib3.PoolManager(
timeout=1.0, retries=urllib3.Retry(total=3, read=False)
)
for lang, link in contribute.custom_contributing_links.items():
with self.subTest(lang=lang):
link = link.format(branch='3.12' if lang == 'tr' else '3.14')
with self.subTest(lang=lang, link=link):
try:
r = http.request('HEAD', link, timeout=urllib3.Timeout(10.0))
self.assertTrue(
200 <= r.status < 400, f'{link} returned {r.status}'
)
except urllib3.exceptions.MaxRetryError as e:
if isinstance(e.reason, urllib3.exceptions.ReadTimeoutError):
self.skipTest(f'{link}: read timeout, skipping slow server')
self.fail(f'{link}: {e}')
except urllib3.exceptions.HTTPError as e:
self.fail(f'{link}: {e}')
response = http.request('HEAD', link)
except urllib3.exceptions.ReadTimeoutError:
self.skipTest(f'{link}: read timeout, skipping slow server')
self.assertTrue(
200 <= response.status < 400, f'{link} returned {response.status}'
)


if __name__ == '__main__':
Expand Down
Loading