Florent VanDeMoortele
12/05/2023, 11:04 AMMarvin
12/05/2023, 11:05 AMautodoc
to the list of enabled extensions in your conf.py
file. It should look something like this:
extensions = [
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx.ext.autodoc',
]
2. Move the content of the .. py:function
directive to the function docstring in the original Python file.
3. If you are documenting decorated functions or methods, keep in mind that autodoc retrieves its docstrings by importing the module and inspecting the __doc__
attribute of the given function or method.
4. From Python 2.5, functools.wraps()
can be used to create well-behaved decorating functions. So, using functools.wraps()
in your decorators will ensure that the docstrings are preserved and can be retrieved by autodoc.
5. Finally, you can use sphinx-apidoc
, a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools.
Here are some resources that might help you:
- Sphinx autodoc extension
- StackOverflow: How to autodoc decorated methods with sphinx?
- Sphinx tutorial: Automatic documentation generation from code
- Sphinx-apidoc documentation
- StackOverflow: How to get docstrings from decorated functions in Python with autodoc?
Remember, the key is to ensure that your decorators are well-behaved and preserve the docstrings of the functions they decorate.