Skip to content

Commit 24d811b

Browse files
authored
Clarify and improve documentation. (#43)
1 parent 8bcc37e commit 24d811b

File tree

17 files changed

+279
-148
lines changed

17 files changed

+279
-148
lines changed

doc-source/_static/style.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
p {
2+
margin-bottom: 12px;
3+
}

doc-source/api/autoenum.rst

Lines changed: 135 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,138 @@
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+
---------------
4135

5136
.. automodule:: enum_tools.autoenum
137+
:no-docstring:
6138
:exclude-members: innernodeclass

doc-source/api/custom_enums.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
:mod:`enum_tools.custom_enums`
33
===================================
44

5+
.. autosummary-widths:: 30/100
56
.. automodule:: enum_tools.custom_enums

doc-source/api/documentation.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
:mod:`enum_tools.documentation`
33
===================================
44

5+
.. module:: enum_tools.documentation
6+
.. autosummary-widths:: 35/100
57

68
Core Functionality
79
--------------------
@@ -18,13 +20,13 @@ Core Functionality
1820
.. autofunction:: enum_tools.documentation.document_member
1921

2022

21-
23+
.. latex:clearpage::
2224
2325
Utilities
2426
--------------------
2527

2628
.. automodulesumm:: enum_tools.documentation
27-
:exclude-members: DocumentedEnum,document_enum,document_member
29+
:autosummary-exclude-members: DocumentedEnum,document_enum,document_member
2830

2931
.. autofunction:: enum_tools.documentation.get_base_indent
3032

doc-source/api/utils.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
:mod:`enum_tools.utils`
33
=========================
44

5+
.. autosummary-widths:: 35/100
56
.. automodule:: enum_tools.utils

doc-source/autoenum.rst

Lines changed: 0 additions & 83 deletions
This file was deleted.

doc-source/conf.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,21 @@ def setup(app):
7373

7474

7575
html_logo = "../enum_tools.png"
76+
autosummary_widths_builders = ["latex"]
77+
nitpicky = True
78+
needspace_amount = "1\\baselineskip"
79+
ignore_missing_xrefs = [
80+
"^sphinx.ext.autodoc.(Class|Attribute)?Documenter$",
81+
"^enum.EnumMeta$",
82+
"^docutils.nodes.Element$",
83+
"^sphinx.domains"
84+
]
85+
# stdlib
86+
from typing import Type
87+
88+
# 3rd party
89+
import enum_tools.autoenum
90+
from sphinx.ext.autodoc.directive import DocumenterBridge
91+
92+
enum_tools.autoenum.DocumenterBridge = DocumenterBridge
93+
enum_tools.autoenum.Type = Type

doc-source/contributing.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
Overview
2-
---------
1+
==============
2+
Contributing
3+
==============
34

45
.. This file based on https://github.com/PyGithub/PyGithub/blob/master/CONTRIBUTING.md
56

doc-source/index.rst

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,19 @@ Enum Tools
134134
.. end shields
135135
136136
137-
This library provides the following:
137+
Overview
138+
------------
139+
140+
.. latex-section::
138141

139-
#. A decorator to add docstrings to ``Enum`` members from a comment at the end of the line.
140142

141-
#. A ``Sphinx`` extension to document Enums better than :rst:dir:`autoclass` can currently.
143+
This library provides the following:
142144

143-
#. Additional ``Enum`` classes with different functionality.
145+
#. :mod:`enum_tools.autoenum` -- A `Sphinx <https://www.sphinx-doc.org>`_ extension to document Enums better than :rst:dir:`autoclass`
146+
can currently.
147+
#. :deco:`enum_tools.documentation.document_enum` -- A decorator to add docstrings to :class:`~enum.Enum` members
148+
from a comment at the end of the line.
149+
#. :mod:`enum_tools.custom_enums` -- Additional :class:`~enum.Enum` classes with different functionality.
144150

145151

146152
Installation
@@ -156,30 +162,34 @@ Installation
156162

157163
.. end installation
158164
159-
.. toctree::
160-
:hidden:
161165
162-
Home<self>
166+
Contents
167+
------------
168+
169+
.. html-section::
170+
163171

164172
.. toctree::
165-
:maxdepth: 3
166-
:caption: Documentation
173+
:hidden:
167174

168-
autoenum
175+
Home<self>
169176

170177
.. toctree::
171178
:maxdepth: 3
172-
:caption: API Reference
173179
:glob:
174180

175181
api/*
176182

177-
.. toctree::
178-
:maxdepth: 3
179-
:caption: Contributing
180183

181-
contributing
182-
Source
184+
.. only:: html
185+
186+
.. toctree::
187+
:maxdepth: 3
188+
:glob:
189+
190+
contributing
191+
Source
192+
license
183193

184194
.. sidebar-links::
185195
:caption: Links
@@ -195,16 +205,17 @@ Installation
195205

196206
:github:repo:`Browse the GitHub Repository <domdfcoding/enum_tools>`
197207

198-
.. end links
199208

200209

201210
Further Reading
202211
-----------------------
203212

204-
#. https://docs.python.org/3/library/enum.html
213+
.. html-section::
205214

206-
#. `Is it possible to define a class constant inside an Enum? <https://stackoverflow.com/q/17911188/3092681>`_
207215

208-
#. `Enums with Attributes <https://stackoverflow.com/a/19300424/3092681>`_
216+
.. only:: html
209217

210-
#. `When should I subclass EnumMeta instead of Enum? <https://stackoverflow.com/a/43730306/3092681>`_
218+
* https://docs.python.org/3/library/enum.html
219+
* `Is it possible to define a class constant inside an Enum? <https://stackoverflow.com/q/17911188/3092681>`_
220+
* `Enums with Attributes <https://stackoverflow.com/a/19300424/3092681>`_
221+
* `When should I subclass EnumMeta instead of Enum? <https://stackoverflow.com/a/43730306/3092681>`_

doc-source/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
git+https://github.com/sphinx-toolbox/sphinx-toolbox-experimental
12
default-values>=0.5.0
23
domdf-sphinx-theme>=0.3.0
34
extras-require>=0.2.0

0 commit comments

Comments
 (0)