Skip to content

Commit

Permalink
Replace custom 'source' role with extlink
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Apr 13, 2024
1 parent 997128c commit 69683a3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
sys.path.append(os.path.abspath('tools/extensions'))
sys.path.append(os.path.abspath('includes'))

from pyspecific import SOURCE_URI

# General configuration
# ---------------------

Expand Down Expand Up @@ -525,6 +527,7 @@
"cve": ("https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s", "CVE-%s"),
"cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
"pypi": ("https://pypi.org/project/%s/", "%s"),
"source": (SOURCE_URI, "%s"),
}

# Options for extensions
Expand Down
15 changes: 2 additions & 13 deletions Doc/tools/extensions/pyspecific.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from sphinx.locale import _ as sphinx_gettext
from sphinx.util import logging
from sphinx.util.docutils import SphinxDirective
from sphinx.util.nodes import split_explicit_title
from sphinx.writers.text import TextWriter, TextTranslator

try:
Expand All @@ -39,6 +38,7 @@

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/main/%s'

# monkey-patch reST parser to disable alphabetic and roman enumerated lists
Expand All @@ -54,6 +54,7 @@

std.token_re = re.compile(r'`((~?[\w-]*:)?\w+)`')


# Support for marking up and linking to bugs.python.org issues

def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
Expand Down Expand Up @@ -85,16 +86,6 @@ def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
return [refnode], []


# Support for linking to Python source files easily

def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
has_t, title, target = split_explicit_title(text)
title = utils.unescape(title)
target = utils.unescape(target)
refnode = nodes.reference(title, title, refuri=SOURCE_URI % target)
return [refnode], []


# Support for marking up implementation details

class ImplementationDetail(Directive):
Expand Down Expand Up @@ -194,7 +185,6 @@ def parse_platforms(self):
return platforms



# Support for documenting audit event

def audit_events_purge(app, env, docname):
Expand Down Expand Up @@ -710,7 +700,6 @@ def patch_pairindextypes(app, _env) -> None:
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)
app.add_directive('audit-event', AuditEvent)
Expand Down

0 comments on commit 69683a3

Please sign in to comment.