|
43 | 43 | import suspicious
|
44 | 44 |
|
45 | 45 |
|
46 |
| -ISSUE_URI = 'https://bugs.python.org/issue%s' |
| 46 | +ISSUE_URI = 'https://bugs.python.org/issue?@action=redirect&bpo=%s' |
| 47 | +GH_ISSUE_URI = 'https://github.com/python/cpython/issues/%s' |
47 | 48 | SOURCE_URI = 'https://github.com/python/cpython/tree/3.8/%s'
|
48 | 49 |
|
49 | 50 | # monkey-patch reST parser to disable alphabetic and roman enumerated lists
|
|
58 | 59 |
|
59 | 60 | def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
60 | 61 | 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] |
61 | 68 | text = 'bpo-' + issue
|
62 | 69 | refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
|
63 | 70 | return [refnode], []
|
64 | 71 |
|
65 | 72 |
|
| 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 | + |
66 | 89 | # Support for linking to Python source files easily
|
67 | 90 |
|
68 | 91 | def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
@@ -575,6 +598,7 @@ def process_audit_events(app, doctree, fromdocname):
|
575 | 598 |
|
576 | 599 | def setup(app):
|
577 | 600 | app.add_role('issue', issue_role)
|
| 601 | + app.add_role('gh', gh_issue_role) |
578 | 602 | app.add_role('source', source_role)
|
579 | 603 | app.add_directive('impl-detail', ImplementationDetail)
|
580 | 604 | app.add_directive('availability', Availability)
|
|
0 commit comments