Skip to content

Commit

Permalink
pythongh-91888: Add a :gh: role to the documentation (pythonGH-91889).
Browse files Browse the repository at this point in the history
  • Loading branch information
ezio-melotti committed Apr 26, 2022
1 parent d35af52 commit ac050e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
import suspicious


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

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

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


# Support for marking up and linking to GitHub issues

def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
issue = utils.unescape(text)
# sanity check: all GitHub issues have ID >= 32426
# even though some of them are also valid BPO IDs
if int(issue) < 32426:
msg = inliner.reporter.error(f'The GitHub ID {text!r} seems too low -- '
'use :issue:`...` for BPO IDs', line=lineno)
prb = inliner.problematic(rawtext, rawtext, msg)
return [prb], [msg]
text = 'gh-' + issue
refnode = nodes.reference(text, text, refuri=GH_ISSUE_URI % issue)
return [refnode], []


# Support for linking to Python source files easily

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

def setup(app):
app.add_role('issue', issue_role)
app.add_role('gh', gh_issue_role)
app.add_role('source', source_role)
app.add_directive('impl-detail', ImplementationDetail)
app.add_directive('availability', Availability)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a new `gh` role to the documentation to link to GitHub issues.

0 comments on commit ac050e9

Please sign in to comment.