8000 [3.7] gh-91888: add a `:gh:` role to the documentation (GH-91889) (GH… · python/cpython@73317e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73317e3

Browse files
authored
[3.7] gh-91888: add a :gh: role to the documentation (GH-91889) (GH-91937)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>. Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com> (cherry picked from commit f7641a2)
1 parent 5da1197 commit 73317e3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Doc/tools/extensions/pyspecific.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737

3838
ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s'
39+
GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s'
3940
SOURCE_URI = 'https://github.com/python/cpython/tree/3.7/%s'
4041

4142
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
@@ -81,11 +82,33 @@ def new_depart_literal_block(self, node):
8182

8283
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
8384
issue = utils.unescape(text)
85+
# sanity check: there are no bpo issues within these two values
86+
if 47261 < int(issue) < 400000:
87+
msg = inliner.reporter.error(f'The BPO ID {text!r} seems too high -- '
88+
'use :gh:`...` for GitHub IDs', line=lineno)
89+
prb = inliner.problematic(rawtext, rawtext, msg)
90+
return [prb], [msg]
8491
text = 'bpo-' + issue
8592
refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
8693
return [refnode], []
8794

8895

96+
# Support for marking up and linking to GitHub issues
97+
98+
def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
99+
issue = utils.unescape(text)
100+
# sanity check: all GitHub issues have ID >= 32426
101+
# even though some of them are also valid BPO IDs
102+
if int(issue) < 32426:
103+
msg = inliner.reporter.error(f'The GitHub ID {text!r} seems too low -- '
104+
'use :issue:`...` for BPO IDs', line=lineno)
105+
prb = inliner.problematic(rawtext, rawtext, msg)
106+
return [prb], [msg]
107+
text = 'gh-' + issue
108+
refnode = nodes.reference(text, text, refuri=GH_ISSUE_URI % issue)
109+
return [refnode], []
110+
111+
89112
# Support for linking to Python source files easily
90113

91114
def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
@@ -431,6 +454,7 @@ def parse_pdb_command(env, sig, signode):
431454

432455
def setup(app):
433456
app.add_role('issue', issue_role)
457+
app.add_role('gh', gh_issue_role)
434458
app.add_role('source', source_role)
435459
app.add_directive('impl-detail', ImplementationDetail)
436460
app.add_directive('availability', Availability)
Lines changed: 1 addition & 0 deletions
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)
0