Skip to content

Commit 3f51f1a

Browse files
committed
Merge branch '4.x'
2 parents 3d8fbd9 + 481c5e9 commit 3f51f1a

File tree

181 files changed

+3749
-2993
lines changed

Some content is hidden

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

181 files changed

+3749
-2993
lines changed

CHANGES

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,57 @@ Dependencies
2828
Incompatible changes
2929
--------------------
3030

31+
* #9649: ``searchindex.js``: the embedded data has changed format to allow
32+
objects with the same name in different domains.
33+
* #9672: The rendering of Python domain declarations is implemented
34+
with more docutils nodes to allow better CSS styling.
35+
It may break existing styling.
36+
* #9672: the signature of
37+
:py:meth:`domains.py.PyObject.get_signature_prefix` has changed to
38+
return a list of nodes instead of a plain string.
39+
* #9695: ``domains.js.JSObject.display_prefix`` has been changed into a method
40+
``get_display_prefix`` which now returns a list of nodes
41+
instead of a plain string.
42+
* #9695: The rendering of Javascript domain declarations is implemented
43+
with more docutils nodes to allow better CSS styling.
44+
It may break existing styling.
45+
46+
3147
Deprecated
3248
----------
3349

3450
Features added
3551
--------------
3652

53+
* #9639: autodoc: Support asynchronous generator functions
54+
* #9664: autodoc: ``autodoc-process-bases`` supports to inject reST snippet as a
55+
base class
56+
* #9691: C, added new info-field ``retval``
57+
for :rst:dir:`c:function` and :rst:dir:`c:macro`.
58+
* C++, added new info-field ``retval`` for :rst:dir:`cpp:function`.
59+
* #9672: More CSS classes on Python domain descriptions
60+
* #9695: More CSS classes on Javascript domain descriptions
61+
3762
Bugs fixed
3863
----------
3964

65+
* #9630: autodoc: Failed to build cross references if :confval:`primary_domain`
66+
is not 'py'
67+
* #9644: autodoc: Crashed on getting source info from problematic object
68+
* #9655: autodoc: mocked object having doc comment is warned unexpectedly
69+
* #9651: autodoc: return type field is not generated even if
70+
:confval:`autodoc_typehints_description_target` is set to "documented" when
71+
its info-field-list contains ``:returns:`` field
72+
* #9657: autodoc: The base class for a subclass of mocked object is incorrect
73+
* #9607: autodoc: Incorrect base class detection for the subclasses of the
74+
generic class
75+
* #9630: autosummary: Failed to build summary table if :confval:`primary_domain`
76+
is not 'py'
77+
* #9670: html: Fix download file with special characters
78+
* #9649: HTML search: when objects have the same name but in different domains,
79+
return all of them as result instead of just one.
80+
* #9678: linkcheck: file extension was shown twice in warnings
81+
4082
Testing
4183
--------
4284

@@ -131,6 +173,7 @@ Bugs fixed
131173
with the HEAD of 3.10
132174
* #9436, #9471: autodoc: crashed if ``autodoc_class_signature = "separated"``
133175
* #9456: html search: html_copy_source can't control the search summaries
176+
* #9500: LaTeX: Failed to build Japanese document on Windows
134177
* #9435: linkcheck: Failed to check anchors in github.com
135178

136179
Release 4.1.1 (released Jul 15, 2021)

doc/_static/conf.py.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# test documentation build configuration file, created by
22
# sphinx-quickstart on Sun Jun 26 00:00:43 2016.
33
#
4-
# This file is execfile()d with the current directory set to its
5-
# containing dir.
4+
# This file is executed through importlib.import_module with
5+
# the current directory set to its containing dir.
66
#
77
# Note that not all possible configuration values are present in this
88
# autogenerated file.
25.9 KB
Loading
70.1 KB
Loading
40.8 KB
Loading

doc/_templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ <h2>{%trans%}Contributor Guide{%endtrans%}</h2>
118118
this part of the documentation is for you.{%endtrans%}</p>
119119

120120
<ul>
121-
<li>{%trans path=pathto("internals/contributing")%}<a href="{{ path }}">Sphinx Contributors’s Guide</a></li>{%endtrans%}
121+
<li>{%trans path=pathto("internals/contributing")%}<a href="{{ path }}">Sphinx Contributors’ Guide</a></li>{%endtrans%}
122122
<li>{%trans path=pathto("internals/authors")%}<a href="{{ path }}">Sphinx Authors</a></li>{%endtrans%}
123123
</ul>
124124

doc/extdev/builderapi.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Builder API
1616
.. autoattribute:: name
1717
.. autoattribute:: format
1818
.. autoattribute:: epilog
19+
.. autoattribute:: allow_parallel
1920
.. autoattribute:: supported_image_types
2021
.. autoattribute:: supported_remote_images
2122
.. autoattribute:: supported_data_uri_images

doc/extdev/deprecated.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,11 @@ The following is a list of deprecated interfaces.
748748
- 4.0
749749
- ``sphinx.domains.std.StandardDomain.process_doc()``
750750

751+
* - ``sphinx.domains.js.JSObject.display_prefix``
752+
-
753+
- 4.3
754+
- ``sphinx.domains.js.JSObject.get_display_prefix()``
755+
751756
* - ``sphinx.environment.NoUri``
752757
- 2.1
753758
- 3.0

doc/extdev/domainapi.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Domain API
1313
.. autoclass:: Index
1414
:members:
1515

16+
.. module:: sphinx.directives
17+
18+
.. autoclass:: ObjectDescription
19+
:members:
1620

1721
Python Domain
1822
-------------
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
Automatic documentation generation from code
2+
============================================
3+
4+
In the :ref:`previous section <tutorial-describing-objects>` of the tutorial
5+
you manually documented a Python function in Sphinx. However, the description
6+
was out of sync with the code itself, since the function signature was not
7+
the same. Besides, it would be nice to reuse `Python
8+
docstrings <https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring>`_
9+
in the documentation, rather than having to write the information in two
10+
places.
11+
12+
Fortunately, :doc:`the autodoc extension </usage/extensions/autodoc>` provides this
13+
functionality.
14+
15+
Reusing signatures and docstrings with autodoc
16+
----------------------------------------------
17+
18+
To use autodoc, first add it to the list of enabled extensions:
19+
20+
.. code-block:: python
21+
:caption: docs/source/conf.py
22+
:emphasize-lines: 4
23+
24+
extensions = [
25+
'sphinx.ext.duration',
26+
'sphinx.ext.doctest',
27+
'sphinx.ext.autodoc',
28+
]
29+
30+
Next, move the content of the ``.. py:function`` directive to the function
31+
docstring in the original Python file, as follows:
32+
33+
.. code-block:: python
34+
:caption: lumache.py
35+
:emphasize-lines: 2-11
36+
37+
def get_random_ingredients(kind=None):
38+
"""
39+
Return a list of random ingredients as strings.
40+
41+
:param kind: Optional "kind" of ingredients.
42+
:type kind: list[str] or None
43+
:raise lumache.InvalidKindError: If the kind is invalid.
44+
:return: The ingredients list.
45+
:rtype: list[str]
46+
47+
"""
48+
return ["shells", "gorgonzola", "parsley"]
49+
50+
Finally, replace the ``.. py:function`` directive from the Sphinx documentation
51+
with :rst:dir:`autofunction`:
52+
53+
.. code-block:: rst
54+
:caption: docs/source/usage.rst
55+
:emphasize-lines: 3
56+
57+
you can use the ``lumache.get_random_ingredients()`` function:
58+
59+
.. autofunction:: lumache.get_random_ingredients
60+
61+
If you now build the HTML documentation, the output will be the same!
62+
With the advantage that it is generated from the code itself.
63+
Sphinx took the reStructuredText from the docstring and included it,
64+
also generating proper cross-references.
65+
66+
You can also autogenerate documentation from other objects. For example, add
67+
the code for the ``InvalidKindError`` exception:
68+
69+
.. code-block:: python
70+
:caption: lumache.py
71+
72+
class InvalidKindError(Exception):
73+
"""Raised if the kind is invalid."""
74+
pass
75+
76+
And replace the ``.. py:exception`` directive with :rst:dir:`autoexception`
77+
as follows:
78+
79+
.. code-block:: rst
80+
:caption: docs/source/usage.rst
81+
:emphasize-lines: 4
82+
83+
or ``"veggies"``. Otherwise, :py:func:`lumache.get_random_ingredients`
84+
will raise an exception.
85+
86+
.. autoexception:: lumache.InvalidKindError
87+
88+
And again, after running ``make html``, the output will be the same as before.
89+
90+
Generating comprehensive API references
91+
---------------------------------------
92+
93+
While using ``sphinx.ext.autodoc`` makes keeping the code and the documentation
94+
in sync much easier, it still requires you to write an ``auto*`` directive
95+
for every object you want to document. Sphinx provides yet another level of
96+
automation: the :doc:`autosummary </usage/extensions/autosummary>` extension.
97+
98+
The :rst:dir:`autosummary` directive generates documents that contain all the
99+
necessary ``autodoc`` directives. To use it, first enable the autosummary
100+
extension:
101+
102+
.. code-block:: python
103+
:caption: docs/source/conf.py
104+
:emphasize-lines: 5
105+
106+
extensions = [
107+
'sphinx.ext.duration',
108+
'sphinx.ext.doctest',
109+
'sphinx.ext.autodoc',
110+
'sphinx.ext.autosummary',
111+
]
112+
113+
Next, create a new ``api.rst`` file with these contents:
114+
115+
.. code-block:: rst
116+
:caption: docs/source/api.rst
117+
118+
API
119+
===
120+
121+
.. autosummary::
122+
:toctree: generated
123+
124+
lumache
125+
126+
Remember to include the new document in the root toctree:
127+
128+
.. code-block:: rst
129+
:caption: docs/source/index.rst
130+
:emphasize-lines: 7
131+
132+
Contents
133+
--------
134+
135+
.. toctree::
136+
137+
usage
138+
api
139+
140+
Finally, after you build the HTML documentation running ``make html``, it will
141+
contain two new pages:
142+
143+
- ``api.html``, corresponding to ``docs/source/api.rst`` and containing a table
144+
with the objects you included in the ``autosummary`` directive (in this case,
145+
only one).
146+
- ``generated/lumache.html``, corresponding to a newly created reST file
147+
``generated/lumache.rst`` and containing a summary of members of the module,
148+
in this case one function and one exception.
149+
150+
.. figure:: /_static/tutorial/lumache-autosummary.png
151+
:width: 80%
152+
:align: center
153+
:alt: Summary page created by autosummary
154+
155+
Summary page created by autosummary
156+
157+
Each of the links in the summary page will take you to the places where you
158+
originally used the corresponding ``autodoc`` directive, in this case in the
159+
``usage.rst`` document.
160+
161+
.. note::
162+
163+
The generated files are based on `Jinja2
164+
templates <https://jinja2docs.readthedocs.io/>`_ that
165+
:ref:`can be customized <autosummary-customizing-templates>`,
166+
but that is out of scope for this tutorial.

0 commit comments

Comments
 (0)