|
36 | 36 |
|
37 | 37 |
|
38 | 38 | ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s'
|
| 39 | +GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s' |
39 | 40 | SOURCE_URI = 'https://github.com/python/cpython/tree/3.7/%s'
|
40 | 41 |
|
41 | 42 | # monkey-patch reST parser to disable alphabetic and roman enumerated lists
|
@@ -81,11 +82,33 @@ def new_depart_literal_block(self, node):
|
81 | 82 |
|
82 | 83 | def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
83 | 84 | 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] |
84 | 91 | text = 'bpo-' + issue
|
85 | 92 | refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
|
86 | 93 | return [refnode], []
|
87 | 94 |
|
88 | 95 |
|
| 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 | + |
89 | 112 | # Support for linking to Python source files easily
|
90 | 113 |
|
91 | 114 | def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
@@ -431,6 +454,7 @@ def parse_pdb_command(env, sig, signode):
|
431 | 454 |
|
432 | 455 | def setup(app):
|
433 | 456 | app.add_role('issue', issue_role)
|
| 457 | + app.add_role('gh', gh_issue_role) |
434 | 458 | app.add_role('source', source_role)
|
435 | 459 | app.add_directive('impl-detail', ImplementationDetail)
|
436 | 460 | app.add_directive('availability', Availability)
|
|
0 commit comments