[3.12] GH-121970: Extract ``issue_role`` into a new extension (GH-130615) by miss-islington · Pull Request #130652 · python/cpython
ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s' GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s' # Used in conf.py and updated here by python/release-tools/run_release.py SOURCE_URI = 'https://github.com/python/cpython/tree/3.12/%s'
# Support for marking up and linking to bugs.python.org issues
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): issue = 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 = 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], []
class PyAwaitableMixin(object): def handle_signature(self, sig, signode):
def setup(app): app.add_role('issue', issue_role) app.add_role('gh', gh_issue_role) app.add_object_type('opcode', 'opcode', '%s (opcode)', parse_opcode_signature) app.add_object_type('pdbcommand', 'pdbcmd', '%s (pdb command)', parse_pdb_command) app.add_object_type('monitoring-event', 'monitoring-event', '%s (monitoring event)', parse_monitoring_event)