diff --git a/contribute.py b/contribute.py index eb17d4e80..1f60f3329 100644 --- a/contribute.py +++ b/contribute.py @@ -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/' ) diff --git a/generate.py b/generate.py index 23a751dcd..879a6a84c 100644 --- a/generate.py +++ b/generate.py @@ -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), ) diff --git a/tests/test_contribute.py b/tests/test_contribute.py index 6f99cafa8..b305d456d 100644 --- a/tests/test_contribute.py +++ b/tests/test_contribute.py @@ -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__':