8000 Add the sphinx-codeautolink extension · python/cpython@7c384f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7c384f6

Browse files
committed
Add the sphinx-codeautolink extension
1 parent 13cb8ca commit 7c384f6

File tree

6 files changed

+49
-5
lines changed

6 files changed

+49
-5
lines changed

Doc/_static/custom.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
Style autolinks to reference documentation
3+
(https://sphinx-codeautolink.readthedocs.io/en/latest/examples.html#custom-link-styles)
4+
*/
5+
/*
6+
.sphinx-codeautolink-a {
7+
text-decoration: none !important;
8+
}
9+
*/
10+
11+
/* better for debugging */
12+
.sphinx-codeautolink-a {
13+
text-decoration-style: solid !important;
14+
text-decoration-color: #aaa;
15+
}
16+
.sphinx-codeautolink-a:hover {
17+
text-decoration-color: black;
18+
}

Doc/conf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'sphinx.ext.coverage',
3939
'sphinx.ext.doctest',
4040
'sphinx.ext.extlinks',
41+
'sphinx_codeautolink',
4142
]
4243

4344
# Skip if downstream redistributors haven't installed them
@@ -404,6 +405,9 @@
404405
# Additional static files.
405406
html_static_path = ['_static', 'tools/static']
406407

408+
# Additional CSS files.
409+
html_css_files = ["custom.css"]
410+
407411
# Output file base name for HTML help builder.
408412
htmlhelp_basename = 'python' + release.replace('.', '')
409413

@@ -413,6 +417,16 @@
413417
# Split pot files one per reST file
414418
gettext_compact = False
415419

420+
# Options for automatic links from code examples to reference docs
421+
# (https://sphinx-codeautolink.readthedocs.io/)
422+
codeautolink_warn_on_missing_inventory = False
423+
codeautolink_warn_on_failed_resolve = False
424+
codeautolink_custom_blocks = {
425+
# https://sphinx-codeautolink.readthedocs.io/en/latest/examples.html#doctest-code-blocks
426+
"pycon3": "sphinx_codeautolink.clean_pycon",
427+
}
428+
# suppress_warnings = ["codeautolink"]
429+
416430
# Options for LaTeX output
417431
# ------------------------
418432

Doc/howto/regex.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
with the :mod:`re` module. It provides a gentler introduction than the
2020
corresponding section in the Library Reference.
2121

22+
.. highlight:: pycon
2223

2324
Introduction
2425
============

Doc/library/asyncio-stream.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,17 @@ Simple example querying HTTP headers of the URL passed on the command line::
538538
asyncio.run(print_http_headers(url))
539539

540540

541-
Usage::
541+
Usage:
542542

543-
python example.py http://example.com/path/page.html
543+
.. code-block:: shell
544544
545-
or with HTTPS::
545+
python example.py http://example.com/path/page.html
546546
547-
python example.py https://example.com/path/page.html
547+
or with HTTPS:
548+
549+
.. code-block:: shell
550+
551+
python example.py https://example.com/path/page.html
548552
549553
550554
.. _asyncio_example_create_connection-streams:

Doc/library/asyncio-sync.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Lock
5252
# ... later
5353
async with lock:
5454
# access shared state
55+
...
5556

5657
which is equivalent to::
5758

@@ -61,6 +62,7 @@ Lock
6162
await lock.acquire()
6263
try:
6364
# access shared state
65+
...
6466
finally:
6567
lock.release()
6668

@@ -305,6 +307,7 @@ Semaphore
305307
# ... later
306308
async with sem:
307309
# work with shared resource
310+
...
308311

309312
which is equivalent to::
310313

@@ -314,6 +317,7 @@ Semaphore
314317
await sem.acquire()
315318
try:
316319
# work with shared resource
320+
...
317321
finally:
318322
sem.release()
319323

@@ -397,7 +401,9 @@ Barrier
397401

398402
asyncio.run(example_barrier())
399403

400-
Result of this example is::
404+
Result of this example is:
405+
406+
.. code-block:: none
401407
402408
<asyncio.locks.Barrier object at 0x... [filling, waiters:2/3]>
403409
<asyncio.locks.Barrier object at 0x... [draining, waiters:0/3]>

Doc/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ blurb
1313

1414
sphinxext-opengraph~=0.10.0
1515
sphinx-notfound-page~=1.0.0
16+
sphinx-codeautolink~=0.16.0
1617

1718
# The theme used by the documentation is stored separately, so we need
1819
# to install that as well.

0 commit comments

Comments
 (0)
0