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

Skip to content

Commit f7641a2

Browse files
ezio-melottihugovk
andauthored
gh-91888: add a :gh: role to the documentation (#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>
1 parent 4403320 commit f7641a2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

Doc/tools/extensions/pyspecific.py

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

4545

4646
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/main/%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=[]):
@@ -615,6 +638,7 @@ def process_audit_events(app, doctree, fromdocname):
615638

616639
def setup(app):
617640
app.add_role('issue', issue_role)
641+
app.add_role('gh', gh_issue_role)
618642
app.add_role('source', source_role)
619643
app.add_directive('impl-detail', ImplementationDetail)
620644
app.add_directive('availability', Availability)

Doc/whatsnew/3.11.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ inspect
463463
line number, column and end column). The affected functions are:
464464
:func:`inspect.getframeinfo`, :func:`inspect.getou 86C6 terframes`, :func:`inspect.getinnerframes`,
465465
:func:`inspect.stack` and :func:`inspect.trace`. (Contributed by Pablo Galindo in
466-
:issue:`88116`)
466+
:gh:`88116`)
467467

468468
locale
469469
------
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