|
1 | | -=================================== |
2 | | -:mod:`enum_tools.autoenum` |
3 | | -=================================== |
| 1 | +================================================ |
| 2 | +:mod:`enum_tools.autoenum` -- Sphinx Extension |
| 3 | +================================================ |
| 4 | + |
| 5 | +A Sphinx directive for documenting :class:`Enums <enum.Enum>` in Python. |
| 6 | + |
| 7 | +Provides the :rst:dir:`autoenum` directive for documenting :class:`Enums <enum.Enum>`, |
| 8 | +and :rst:dir:`autoflag` for documenting :class:`Flags <enum.Flag>`. |
| 9 | +These behaves much like :rst:dir:`autoclass` and :rst:dir:`autofunction`. |
| 10 | + |
| 11 | +.. extras-require:: sphinx |
| 12 | + :pyproject: |
| 13 | + :scope: extension / module |
| 14 | + |
| 15 | +.. extensions:: enum_tools.autoenum |
| 16 | + |
| 17 | +.. contents:: Sections |
| 18 | + :depth: 1 |
| 19 | + :local: |
| 20 | + :backlinks: none |
| 21 | + |
| 22 | + |
| 23 | +Usage |
| 24 | +--------- |
| 25 | + |
| 26 | +.. rst:directive:: autoenum |
| 27 | + autoflag |
| 28 | +
|
| 29 | + These directives are used for documenting :class:`Enums <enum.Enum>` and :class:`Flags <enum.Flag>` respectively. |
| 30 | + |
| 31 | + They support the same options as :rst:dir:`autoclass`, but with a few changes to the behaviour: |
| 32 | + |
| 33 | + * Enum members are always shown regardless of whether they are documented or not. |
| 34 | + * Enum members are grouped separately from methods. |
| 35 | + |
| 36 | + The docstrings of the Enum members are taken from their ``__doc__`` attributes. |
| 37 | + This can be set during initialisation of the enum (see an example `here <https://stackoverflow.com/a/50473952>`_), |
| 38 | + with the :class:`~enum_tools.documentation.DocumentedEnum` class, or with the :func:`~enum_tools.documentation.document_enum` decorator. |
| 39 | + |
| 40 | + See the `autodoc module documentation`_ for further details |
| 41 | + of the general :rst:dir:`autoclass` behaviour. |
| 42 | + |
| 43 | + .. _autodoc module documentation: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html |
| 44 | + |
| 45 | + |
| 46 | +.. rst:role:: py:enum:mem |
| 47 | + py:enum:member |
| 48 | + py:flag:mem |
| 49 | + py:flag:member |
| 50 | +
|
| 51 | + These roles provide cross-references to Enum/Flag members. |
| 52 | + |
| 53 | + .. versionadded:: 0.4.0 |
| 54 | + |
| 55 | + Unlike a standard ``:class:`` or ``:enum:`` xref the default behaviour of the |
| 56 | + ``~`` prefix is to show both the Enum's name and the member's name. |
| 57 | + For example: |
| 58 | + |
| 59 | + .. rest-example:: |
| 60 | + |
| 61 | + :py:enum:mem:`~enum_tools.demo.StatusFlags.Running` |
| 62 | + |
| 63 | + The original behaviour can be restored by using the ``+`` prefix: |
| 64 | + |
| 65 | + .. rest-example:: |
| 66 | + |
| 67 | + :py:enum:mem:`+enum_tools.demo.StatusFlags.Running` |
| 68 | + |
| 69 | + |
| 70 | +.. latex:vspace:: 10px |
| 71 | +
|
| 72 | +Demo |
| 73 | +---------- |
| 74 | + |
| 75 | +**These two have been created with** ``automodule``. |
| 76 | + |
| 77 | +.. container:: rest-example |
| 78 | + |
| 79 | + .. code-block:: rest |
| 80 | +
|
| 81 | + .. automodule:: enum_tools.demo |
| 82 | + :members: |
| 83 | +
|
| 84 | + .. automodule:: enum_tools.demo |
| 85 | + :members: |
| 86 | + :exclude-members: NoMemberDoc,StatusFlags,People |
| 87 | + :noindex: |
| 88 | + :no-autosummary: |
| 89 | + |
| 90 | + .. latex:clearpage:: |
| 91 | +
|
| 92 | + .. automodule:: enum_tools.demo |
| 93 | + :members: |
| 94 | + :exclude-members: NoMemberDoc,StatusFlags,NoMethods |
| 95 | + :noindex: |
| 96 | + :no-autosummary: |
| 97 | + |
| 98 | +.. raw:: html |
| 99 | + |
| 100 | + <p></p> |
| 101 | + |
| 102 | + |
| 103 | +.. latex:vspace:: 10px |
| 104 | +
|
| 105 | +**This one has been created with** ``autoenum``. |
| 106 | + |
| 107 | +.. rest-example:: |
| 108 | + |
| 109 | + .. autoenum:: enum_tools.demo.People |
| 110 | + :members: |
| 111 | + |
| 112 | + |
| 113 | +.. latex:clearpage:: |
| 114 | +
|
| 115 | +**If members don't have their own docstrings no docstring is shown:** |
| 116 | + |
| 117 | +.. rest-example:: |
| 118 | + |
| 119 | + .. autoenum:: enum_tools.demo.NoMemberDoc |
| 120 | + :members: |
| 121 | + |
| 122 | + |
| 123 | +.. latex:vspace:: 10px |
| 124 | +
|
| 125 | +**Flags can also be documented:** |
| 126 | + |
| 127 | +.. rest-example:: |
| 128 | + |
| 129 | + .. autoflag:: enum_tools.demo.StatusFlags |
| 130 | + :members: |
| 131 | + |
| 132 | + |
| 133 | +API Reference |
| 134 | +--------------- |
4 | 135 |
|
5 | 136 | .. automodule:: enum_tools.autoenum |
| 137 | + :no-docstring: |
6 | 138 | :exclude-members: innernodeclass |
0 commit comments