Skip to content

Commit f46f74d

Browse files
authored
Merge pull request #2968 from kachida/feat/enable-hoverxref-in-trio-docs
docs: add hoverxref & codeautolink support. Various fixes
2 parents 78666e7 + f0cb052 commit f46f74d

11 files changed

+265
-85
lines changed

docs-requirements.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ sphinx_rtd_theme
66
sphinxcontrib-jquery
77
sphinxcontrib-trio
88
towncrier
9+
sphinx-hoverxref
10+
sphinx-codeautolink
911

1012
# Trio's own dependencies
1113
cffi; os_name == "nt"

docs-requirements.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ attrs==23.2.0
1212
# outcome
1313
babel==2.14.0
1414
# via sphinx
15+
beautifulsoup4==4.12.3
16+
# via sphinx-codeautolink
1517
certifi==2024.2.2
1618
# via requests
1719
cffi==1.16.0
@@ -69,12 +71,20 @@ snowballstemmer==2.2.0
6971
# via sphinx
7072
sortedcontainers==2.4.0
7173
# via -r docs-requirements.in
74+
soupsieve==2.5
75+
# via beautifulsoup4
7276
sphinx==7.1.2
7377
# via
7478
# -r docs-requirements.in
79+
# sphinx-codeautolink
80+
# sphinx-hoverxref
7581
# sphinx-rtd-theme
7682
# sphinxcontrib-jquery
7783
# sphinxcontrib-trio
84+
sphinx-codeautolink==0.15.0
85+
# via -r docs-requirements.in
86+
sphinx-hoverxref==1.3.0
87+
# via -r docs-requirements.in
7888
sphinx-rtd-theme==2.0.0
7989
# via -r docs-requirements.in
8090
sphinxcontrib-applehelp==1.0.4
@@ -86,6 +96,7 @@ sphinxcontrib-htmlhelp==2.0.1
8696
sphinxcontrib-jquery==4.1
8797
# via
8898
# -r docs-requirements.in
99+
# sphinx-hoverxref
89100
# sphinx-rtd-theme
90101
sphinxcontrib-jsmath==1.0.1
91102
# via sphinx

docs/source/conf.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def setup(app: Sphinx) -> None:
150150
"sphinx.ext.napoleon",
151151
"sphinxcontrib_trio",
152152
"sphinxcontrib.jquery",
153+
"hoverxref.extension",
154+
"sphinx_codeautolink",
153155
"local_customization",
154156
"typevars",
155157
]
@@ -162,6 +164,31 @@ def setup(app: Sphinx) -> None:
162164
"trio-util": ("https://trio-util.readthedocs.io/en/latest/", None),
163165
}
164166

167+
# See https://sphinx-hoverxref.readthedocs.io/en/latest/configuration.html
168+
hoverxref_auto_ref = True
169+
hoverxref_domains = ["py"]
170+
# Set the default style (tooltip) for all types to silence logging.
171+
# See https://github.com/readthedocs/sphinx-hoverxref/issues/211
172+
hoverxref_role_types = {
173+
"attr": "tooltip",
174+
"class": "tooltip",
175+
"const": "tooltip",
176+
"exc": "tooltip",
177+
"func": "tooltip",
178+
"meth": "tooltip",
179+
"mod": "tooltip",
180+
"obj": "tooltip",
181+
"ref": "tooltip",
182+
"data": "tooltip",
183+
}
184+
185+
# See https://sphinx-codeautolink.readthedocs.io/en/latest/reference.html#configuration
186+
codeautolink_autodoc_inject = False
187+
codeautolink_global_preface = """
188+
import trio
189+
from trio import *
190+
"""
191+
165192

166193
def add_intersphinx(app: Sphinx) -> None:
167194
"""Add some specific intersphinx mappings.

docs/source/contributing.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,12 @@ you'll have a chance to see and fix any remaining issues then.
199199
Every change should have 100% coverage for both code and tests. But,
200200
you can use ``# pragma: no cover`` to mark lines where
201201
lack-of-coverage isn't something that we'd want to fix (as opposed to
202-
it being merely hard to fix). For example::
202+
it being merely hard to fix). For example:
203203

204+
.. code-block:: python
205+
206+
if ...:
207+
...
204208
else: # pragma: no cover
205209
raise AssertionError("this can't happen!")
206210
@@ -289,7 +293,9 @@ Instead of wasting time arguing about code formatting, we use `black
289293
<https://github.com/psf/black>`__ as well as other tools to automatically
290294
format all our code to a standard style. While you're editing code you
291295
can be as sloppy as you like about whitespace; and then before you commit,
292-
just run::
296+
just run:
297+
298+
.. code-block::
293299
294300
pip install -U pre-commit
295301
pre-commit
@@ -301,20 +307,26 @@ names, writing useful comments, and making sure your docstrings are
301307
nicely formatted. (black doesn't reformat comments or docstrings.)
302308

303309
If you would like, you can even have pre-commit run before you commit by
304-
running::
310+
running:
311+
312+
.. code-block::
305313
306314
pre-commit install
307315
308316
and now pre-commit will run before git commits. You can uninstall the
309-
pre-commit hook at any time by running::
317+
pre-commit hook at any time by running:
318+
319+
.. code-block::
310320
311321
pre-commit uninstall
312322
313323
314324
Very occasionally, you'll want to override black formatting. To do so,
315325
you can can add ``# fmt: off`` and ``# fmt: on`` comments.
316326

317-
If you want to see what changes black will make, you can use::
327+
If you want to see what changes black will make, you can use:
328+
329+
.. code-block::
318330
319331
black --diff trio
320332
@@ -396,7 +408,9 @@ whitelist in ``docs/source/conf.py``.
396408
To build the docs locally, use our handy ``docs-requirements.txt``
397409
file to install all of the required packages (possibly using a
398410
virtualenv). After that, build the docs using ``make html`` in the
399-
docs directory. The whole process might look something like this::
411+
docs directory. The whole process might look something like this:
412+
413+
.. code-block::
400414
401415
cd path/to/project/checkout/
402416
pip install -r docs-requirements.txt

docs/source/design.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ mean.
312312
This is often a challenging rule to follow – for example, the call
313313
soon code has to jump through some hoops to make it happen – but its
314314
most dramatic influence can seen in Trio's task-spawning interface,
315-
where it motivates the use of "nurseries"::
315+
where it motivates the use of "nurseries":
316+
317+
.. code-block:: python
316318
317319
async def parent():
318320
async with trio.open_nursery() as nursery:
@@ -376,18 +378,22 @@ Specific style guidelines
376378
unconditionally act as cancel+schedule points.
377379

378380
* Any function that takes a callable to run should have a signature
379-
like::
381+
like:
382+
383+
.. code-block:: python
380384
381-
def call_the_thing(fn, *args, kwonly1, kwonly2, ...)::
385+
def call_the_thing(fn, *args, kwonly1, kwonly2):
382386
...
383387
384388
where ``fn(*args)`` is the thing to be called, and ``kwonly1``,
385-
``kwonly2``, ... are keyword-only arguments that belong to
389+
``kwonly2``, are keyword-only arguments that belong to
386390
``call_the_thing``. This applies even if ``call_the_thing`` doesn't
387391
take any arguments of its own, i.e. in this case its signature looks
388-
like::
392+
like:
389393

390-
def call_the_thing(fn, *args)::
394+
.. code-block:: python
395+
396+
def call_the_thing(fn, *args):
391397
...
392398
393399
This allows users to skip faffing about with
@@ -410,12 +416,14 @@ Specific style guidelines
410416
worse, and you get used to the convention pretty quick.
411417

412418
* If it's desirable to have both blocking and non-blocking versions of
413-
a function, then they look like::
419+
a function, then they look like:
420+
421+
.. code-block:: python
414422
415-
async def OPERATION(...):
423+
async def OPERATION(arg1, arg2):
416424
...
417425
418-
def OPERATION_nowait(...):
426+
def OPERATION_nowait(arg1, arg2):
419427
...
420428
421429
and the ``nowait`` version raises :exc:`trio.WouldBlock` if it would block.

docs/source/history.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,9 @@ Highlights
12481248
* The new nursery :meth:`~Nursery.start` method makes it
12491249
easy to perform controlled start-up of long-running tasks. For
12501250
example, given an appropriate ``http_server_on_random_open_port``
1251-
function, you could write::
1251+
function, you could write:
1252+
1253+
.. code-block:: python
12521254
12531255
port = await nursery.start(http_server_on_random_open_port)
12541256
@@ -1490,7 +1492,9 @@ Other changes
14901492
functions, if you're using asyncio you have to use asyncio
14911493
functions, and so forth. (See the discussion of the "async sandwich"
14921494
in the Trio tutorial for more details.) So for example, this isn't
1493-
going to work::
1495+
going to work:
1496+
1497+
.. code-block:: python
14941498
14951499
async def main():
14961500
# asyncio here

0 commit comments

Comments
 (0)