We have a Python project and do this to generate documents:
sphinx-apidoc --module-first -f -o source/ ../src
make html
In recent sphinx (6.1.3), we notice a problem. One of the classes has a class variable that is a Pandas dataframe. The thing is read from a CSV file before the init function and the Sphinx html output has the whole table included in the documentation. I believe this happens because the table is an undocumented member and Sphinx is doing what it thinks is correct. I have tried many fixes, blundering about in the dark.
The defaults for sphinx-autodoc create rst files like this:
.. automodule:: my.app
:members:
:undoc-members:
:show-inheritance:
If I hand edit the rst file, I can stop the bad result from happening. I thought that "no-undoc-members would solve problem, but it does not. However, adding the exclude param really works.
.. automodule:: my.app
:members:
:no-undoc-members:
:show-inheritance:
:exclude-members: form, form_long
The problem with that "fix" is that autodoc has to update the rst files every time, it erases that hand edited rst.
I have tried these approaches to change autodoc behavior.
Add docstrings for the class variable in the Python source. If I specify the docstring, then Sphinx won't print the whole Pandas table will it? It is supposed to work if I specify before a member variable like
#: blah
or after with""" blah """
. Did not help.In source/conf.py add this:
autodoc_default_options = {
'undoc-members': False,
'exclude-members': 'form'
}
However, after adding that to conf.py
, it seems like sphinx-autodoc does not pay attention. It uses same old rst file defaults. Another problem is that, even if it were used, it seems to not allow me to write more than one member in exclude-members
. I mean, I don't know correct format and everything I've tried causes an error in make html
Thanks in advance if you help me see what I'm doing incorrectly.