|
31 | 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
32 | 32 | # ones. |
33 | 33 | extensions = [ |
| 34 | + 'sphinx.ext.extlinks', |
34 | 35 | 'sphinx.ext.intersphinx', |
35 | 36 | 'sphinx.ext.todo', |
36 | 37 | ] |
|
51 | 52 | # The master toctree document. |
52 | 53 | master_doc = 'index' |
53 | 54 |
|
| 55 | +# -- Project information ----------------------------------------------------- |
| 56 | + |
| 57 | +github_url = 'https://github.com' |
| 58 | +github_repo_org = 'pypa' |
| 59 | +github_repo_name = 'packaging.python.org' |
| 60 | +github_repo_slug = f'{github_repo_org}/{github_repo_name}' |
| 61 | +github_repo_url = f'{github_url}/{github_repo_slug}' |
| 62 | +github_repo_issues_url = f'{github_url}/{github_repo_slug}/issues' |
| 63 | +github_sponsors_url = f'{github_url}/sponsors' |
| 64 | + |
54 | 65 | # General information about the project. |
55 | 66 | project = u'Python Packaging User Guide' |
56 | 67 | copyright = u'2013–2019, PyPA' |
|
132 | 143 | 'collapsiblesidebar': True, |
133 | 144 | 'externalrefs': True, |
134 | 145 | 'navigation_depth': 2, |
135 | | - 'issues_url': 'https://github.com/pypa/python-packaging-user-guide/issues' |
| 146 | + 'issues_url': github_repo_issues_url, |
136 | 147 | } |
137 | 148 |
|
138 | 149 | # Add any paths that contain custom themes here, relative to this directory. |
|
350 | 361 | # |
351 | 362 | # texinfo_no_detailmenu = False |
352 | 363 |
|
| 364 | +# -- Options for extlinks extension --------------------------------------- |
| 365 | +extlinks = { |
| 366 | + 'issue': (f'{github_repo_issues_url}/%s', '#'), # noqa: WPS323 |
| 367 | + 'pr': (f'{github_repo_url}/pull/%s', 'PR #'), # noqa: WPS323 |
| 368 | + 'commit': (f'{github_repo_url}/commit/%s', ''), # noqa: WPS323 |
| 369 | + 'gh': (f'{github_url}/%s', 'GitHub: '), # noqa: WPS323 |
| 370 | + 'user': (f'{github_sponsors_url}/%s', '@'), # noqa: WPS323 |
| 371 | +} |
| 372 | + |
353 | 373 | # Example configuration for intersphinx: refer to the Python standard library. |
354 | 374 | intersphinx_mapping = { |
355 | 375 | 'python': ('https://docs.python.org/3', None), |
|
362 | 382 | # The default is False. |
363 | 383 |
|
364 | 384 | todo_include_todos = True |
365 | | - |
366 | | -# Configure the GitHub PR role to point to our project. |
367 | | - |
368 | | -pr_role_github_org_and_project = 'pypa/python-packaging-user-guide' |
369 | | - |
370 | | -# |
371 | | -# Custom plugin code below. |
372 | | -# |
373 | | - |
374 | | - |
375 | | -def setup(app): |
376 | | - app.add_config_value('pr_role_github_org_and_project', None, 'html') |
377 | | - app.add_role('pr', pr_role) |
378 | | - |
379 | | - |
380 | | -def pr_role(name, rawtext, text, lineno, inliner, options={}, content=[]): |
381 | | - """Transforms ':pr:`number`'' to a hyperlink to the referenced pull request |
382 | | - on GitHub.""" |
383 | | - from docutils import nodes |
384 | | - |
385 | | - app = inliner.document.settings.env |
386 | | - project = app.config.pr_role_github_org_and_project |
387 | | - title = '#{}'.format(text) |
388 | | - |
389 | | - uri = 'https://github.com/{}/pull/{}'.format(project, text) |
390 | | - rn = nodes.reference( |
391 | | - title, title, internal=False, refuri=uri, classes=['pr']) |
392 | | - return [rn], [] |
0 commit comments