Skip to content

Commit 0638941

Browse files
authored
[3.8] gh-91888: add a :gh: role to the documentation (GH-91889) (#91936)
* gh-91888: Add a :gh: role to the documentation (GH-91889). * [3.8] gh-91888: add a `:gh:` role to the documentation (GH-91889) * Add a new :gh:`...` role for GitHub issues. * Fix a GitHub id to use the :gh: role. * Add Misc/NEWS entry. * Refactoring and rephrasing. Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>. (cherry picked from commit f7641a2) Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com> * Fix use of the default role in NEWS entry
1 parent bf54487 commit 0638941

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Doc/tools/extensions/pyspecific.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
import suspicious
4444

4545

46-
ISSUE_URI = 'https://bugs.python.org/issue%s'
46+
ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s'
47+
GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s'
4748
SOURCE_URI = 'https://github.com/python/cpython/tree/3.8/%s'
4849

4950
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
@@ -58,11 +59,33 @@
5859

5960
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
6061
issue = utils.unescape(text)
62+
# sanity check: there are no bpo issues within these two values
63+
if 47261 < int(issue) < 400000:
64+
msg = inliner.reporter.error(f'The BPO ID {text!r} seems too high -- '
65+
'use :gh:`...` for GitHub IDs', line=lineno)
66+
prb = inliner.problematic(rawtext, rawtext, msg)
67+
return [prb], [msg]
6168
text = 'bpo-' + issue
6269
refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
6370
return [refnode], []
6471

6572

73+
# Support for marking up and linking to GitHub issues
74+
75+
def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
76+
issue = utils.unescape(text)
77+
# sanity check: all GitHub issues have ID >= 32426
78+
# even though some of them are also valid BPO IDs
79+
if int(issue) < 32426:
80+
msg = inliner.reporter.error(f'The GitHub ID {text!r} seems too low -- '
81+
'use :issue:`...` for BPO IDs', line=lineno)
82+
prb = inliner.problematic(rawtext, rawtext, msg)
83+
return [prb], [msg]
84+
text = 'gh-' + issue
85+
refnode = nodes.reference(text, text, refuri=GH_ISSUE_URI % issue)
86+
return [refnode], []
87+
88+
6689
# Support for linking to Python source files easily
6790

6891
def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
@@ -575,6 +598,7 @@ def process_audit_events(app, doctree, fromdocname):
575598

576599
def setup(app):
577600
app.add_role('issue', issue_role)
601+
app.add_role('gh', gh_issue_role)
578602
app.add_role('source', source_role)
579603
app.add_directive('impl-detail', ImplementationDetail)
580604
app.add_directive('availability', Availability)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a new ``gh`` role to the documentation to link to GitHub issues.

0 commit comments

Comments
 (0)