Skip to content

Commit 3375282

Browse files
hugovkAlexWaygood
andauthored
Docs: add link roles with Sphinx extlinks (#117850)
Co-authored-by: Alex Waygood <[email protected]>
1 parent 78da154 commit 3375282

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+147
-183
lines changed

Doc/conf.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
sys.path.append(os.path.abspath('tools/extensions'))
1313
sys.path.append(os.path.abspath('includes'))
1414

15+
from pyspecific import SOURCE_URI
16+
1517
# General configuration
1618
# ---------------------
1719

@@ -24,6 +26,7 @@
2426
'pyspecific',
2527
'sphinx.ext.coverage',
2628
'sphinx.ext.doctest',
29+
'sphinx.ext.extlinks',
2730
]
2831

2932
# Skip if downstream redistributors haven't installed them
@@ -513,6 +516,19 @@
513516
r'https://unix.org/version2/whatsnew/lp64_wp.html',
514517
]
515518

519+
# Options for sphinx.ext.extlinks
520+
# -------------------------------
521+
522+
# This config is a dictionary of external sites,
523+
# mapping unique short aliases to a base URL and a prefix.
524+
# https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
525+
extlinks = {
526+
"cve": ("https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s", "CVE-%s"),
527+
"cwe": ("https://cwe.mitre.org/data/definitions/%s.html", "CWE-%s"),
528+
"pypi": ("https://pypi.org/project/%s/", "%s"),
529+
"source": (SOURCE_URI, "%s"),
530+
}
531+
extlinks_detect_hardcoded_links = True
516532

517533
# Options for extensions
518534
# ----------------------

Doc/faq/library.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,15 @@ use ``p.read(n)``.
616616
("ptys") instead of pipes. Or you can use a Python interface to Don Libes'
617617
"expect" library. A Python extension that interfaces to expect is called
618618
"expy" and available from https://expectpy.sourceforge.net. A pure Python
619-
solution that works like expect is `pexpect
620-
<https://pypi.org/project/pexpect/>`_.
619+
solution that works like expect is :pypi:`pexpect`.
621620
622621
623622
How do I access the serial (RS232) port?
624623
----------------------------------------
625624
626625
For Win32, OSX, Linux, BSD, Jython, IronPython:
627626
628-
https://pypi.org/project/pyserial/
627+
:pypi:`pyserial`
629628
630629
For Unix, see a Usenet post by Mitch Chapman:
631630

Doc/howto/curses.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ appearance---and the curses library will figure out what control codes
4343
need to be sent to the terminal to produce the right output. curses
4444
doesn't provide many user-interface concepts such as buttons, checkboxes,
4545
or dialogs; if you need such features, consider a user interface library such as
46-
`Urwid <https://pypi.org/project/urwid/>`_.
46+
:pypi:`Urwid`.
4747

4848
The curses library was originally written for BSD Unix; the later System V
4949
versions of Unix from AT&T added many enhancements and new functions. BSD curses
@@ -56,8 +56,7 @@ versions of curses carried by some proprietary Unixes may not support
5656
everything, though.
5757

5858
The Windows version of Python doesn't include the :mod:`curses`
59-
module. A ported version called `UniCurses
60-
<https://pypi.org/project/UniCurses>`_ is available.
59+
module. A ported version called :pypi:`UniCurses` is available.
6160

6261

6362
The Python curses module
@@ -429,8 +428,7 @@ User Input
429428

430429
The C curses library offers only very simple input mechanisms. Python's
431430
:mod:`curses` module adds a basic text-input widget. (Other libraries
432-
such as `Urwid <https://pypi.org/project/urwid/>`_ have more extensive
433-
collections of widgets.)
431+
such as :pypi:`Urwid` have more extensive collections of widgets.)
434432

435433
There are two methods for getting input from a window:
436434

Doc/howto/logging-cookbook.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,7 +1912,7 @@ Subclassing QueueHandler and QueueListener- a ``pynng`` example
19121912
---------------------------------------------------------------
19131913

19141914
In a similar way to the above section, we can implement a listener and handler
1915-
using `pynng <https://pypi.org/project/pynng/>`_, which is a Python binding to
1915+
using :pypi:`pynng`, which is a Python binding to
19161916
`NNG <https://nng.nanomsg.org/>`_, billed as a spiritual successor to ZeroMQ.
19171917
The following snippets illustrate -- you can test them in an environment which has
19181918
``pynng`` installed. Just for variety, we present the listener first.
@@ -3575,9 +3575,8 @@ A Qt GUI for logging
35753575

35763576
A question that comes up from time to time is about how to log to a GUI
35773577
application. The `Qt <https://www.qt.io/>`_ framework is a popular
3578-
cross-platform UI framework with Python bindings using `PySide2
3579-
<https://pypi.org/project/PySide2/>`_ or `PyQt5
3580-
<https://pypi.org/project/PyQt5/>`_ libraries.
3578+
cross-platform UI framework with Python bindings using :pypi:`PySide2`
3579+
or :pypi:`PyQt5` libraries.
35813580

35823581
The following example shows how to log to a Qt GUI. This introduces a simple
35833582
``QtHandler`` class which takes a callable, which should be a slot in the main

Doc/library/codecs.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ Internationalized Domain Names (IDN)). It builds upon the ``punycode`` encoding
14781478
and :mod:`stringprep`.
14791479

14801480
If you need the IDNA 2008 standard from :rfc:`5891` and :rfc:`5895`, use the
1481-
third-party `idna module <https://pypi.org/project/idna/>`_.
1481+
third-party :pypi:`idna` module.
14821482

14831483
These RFCs together define a protocol to support non-ASCII characters in domain
14841484
names. A domain name containing non-ASCII characters (such as

Doc/library/datetime.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ on efficient attribute extraction for output formatting and manipulation.
3737
Package `dateutil <https://dateutil.readthedocs.io/en/stable/>`_
3838
Third-party library with expanded time zone and parsing support.
3939

40-
Package `DateType <https://pypi.org/project/datetype/>`_
40+
Package :pypi:`DateType`
4141
Third-party library that introduces distinct static types to e.g. allow
4242
:term:`static type checkers <static type checker>`
4343
to differentiate between naive and aware datetimes.

Doc/library/importlib.metadata.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ this package can eliminate the need to use the older and less efficient
2626

2727
``importlib.metadata`` operates on third-party *distribution packages*
2828
installed into Python's ``site-packages`` directory via tools such as
29-
`pip <https://pypi.org/project/pip/>`_.
29+
:pypi:`pip`.
3030
Specifically, it works with distributions with discoverable
3131
``dist-info`` or ``egg-info`` directories,
3232
and metadata defined by the `Core metadata specifications <https://packaging.python.org/en/latest/specifications/core-metadata/#core-metadata>`_.
@@ -177,7 +177,7 @@ for more information on entry points, their definition, and usage.
177177
no parameters and always returned a dictionary of entry points, keyed
178178
by group. With ``importlib_metadata`` 5.0 and Python 3.12,
179179
``entry_points`` always returns an ``EntryPoints`` object. See
180-
`backports.entry_points_selectable <https://pypi.org/project/backports.entry-points-selectable>`_
180+
:pypi:`backports.entry_points_selectable`
181181
for compatibility options.
182182

183183
.. versionchanged:: 3.13

Doc/library/itertools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ recipes. Currently, the ``sliding_window()``, ``iter_index()``, and ``sieve()``
791791
recipes are being tested to see whether they prove their worth.
792792

793793
Substantially all of these recipes and many, many others can be installed from
794-
the `more-itertools project <https://pypi.org/project/more-itertools/>`_ found
794+
the :pypi:`more-itertools` project found
795795
on the Python Package Index::
796796

797797
python -m pip install more-itertools

Doc/library/re.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ fine-tuning parameters.
4848

4949
.. seealso::
5050

51-
The third-party `regex <https://pypi.org/project/regex/>`_ module,
51+
The third-party :pypi:`regex` module,
5252
which has an API compatible with the standard library :mod:`re` module,
5353
but offers additional functionality and a more thorough Unicode support.
5454

Doc/library/secrets.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Generate an eight-character alphanumeric password:
155155
.. note::
156156

157157
Applications should not
158-
`store passwords in a recoverable format <https://cwe.mitre.org/data/definitions/257.html>`_,
158+
:cwe:`store passwords in a recoverable format <257>`,
159159
whether plain text or encrypted. They should be salted and hashed
160160
using a cryptographically strong one-way (irreversible) hash function.
161161

0 commit comments

Comments
 (0)