Skip to content

Commit 1bc6e69

Browse files
committed
Use built-in sphinx extlink instead of custom role
1 parent 62525a1 commit 1bc6e69

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

source/conf.py

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
3333
extensions = [
34+
'sphinx.ext.extlinks',
3435
'sphinx.ext.intersphinx',
3536
'sphinx.ext.todo',
3637
]
@@ -51,6 +52,16 @@
5152
# The master toctree document.
5253
master_doc = 'index'
5354

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+
5465
# General information about the project.
5566
project = u'Python Packaging User Guide'
5667
copyright = u'2013–2019, PyPA'
@@ -132,7 +143,7 @@
132143
'collapsiblesidebar': True,
133144
'externalrefs': True,
134145
'navigation_depth': 2,
135-
'issues_url': 'https://github.com/pypa/python-packaging-user-guide/issues'
146+
'issues_url': github_repo_issues_url,
136147
}
137148

138149
# Add any paths that contain custom themes here, relative to this directory.
@@ -350,6 +361,15 @@
350361
#
351362
# texinfo_no_detailmenu = False
352363

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+
353373
# Example configuration for intersphinx: refer to the Python standard library.
354374
intersphinx_mapping = {
355375
'python': ('https://docs.python.org/3', None),
@@ -362,31 +382,3 @@
362382
# The default is False.
363383

364384
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

Comments
 (0)