I am autogenerating documentation for a Python package using Sphinx with the autodoc extension. The issue I am facing is that the autodoc skips any modules with an underscore.
Some modules were underscored to discourage users from importing them. However, the classes inside these underscored files have no underscores.
When I add the underscored module manually to the package_name.rst and ran make html, it shows. So my problem is how to automate that from autodoc.
I am trying to avoid parsing the package_name.rst via a script to add them. I am hoping for an autodoc flag or a hack!
It's perhaps a misconception to think the
..automodule ::directive applied to a package will automatically document sub-modules as members (by comparison with classes, variables, etc).I just tested this but it can not be done using
:private-members:and or:special-members:. Not by writing either option in the.. automodule::directive corresponding to the package. (Trying to set both options inautodoc_default_optionsgives the same result.)The following example of package and module layout:
Using a
.rstwith a single.. automodule::for the package:Minimal example
_private_module.pywith docstrings (public_module.pyis the same except for the title):Does indeed give an empty documentation:
But if you remove the underscore from the module you get the exact same result.
If you are generating the
.rstfiles withsphinx-apidocif using the-Pflag:The generated files will include an
.. automodule::directive for the private modules, this does have the side-effect of also including the:private-members:option as noted in another post "Include __main__.py in sphinx-apidoc generated files".Example explicitly including the
.. automodule::directives:The result: