autodoc: Ignores py-files with beginning underline in filename

17 views
Skip to first unread message

c.b...@posteo.jp

unread,
Mar 2, 2022, 3:21:50 AM3/2/22
to sphinx...@googlegroups.com
I am quite new to sphinx I try to figuring out autodocumenting my
Python code with it. I have setup a test-project [1] to play around
with some settings.

It seams like that autodoc ignores py-files that start with an
underline; e.g. "_mypackage.py". I looked into the docu [2] but
couldn't find a setting to explain/modify that behavior.

Maybe I am totaly wrong and sphinx.ext.autodoc is not responsible for
that?

[1] -- <https://codeberg.org/buhtz/sphinx_versuch>
[2] -- <https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>

Stephen Finucane

unread,
Mar 8, 2022, 7:33:09 AM3/8/22
to sphinx...@googlegroups.com
On Wed, 2022-03-02 at 08:21 +0000, c.b...@posteo.jp wrote:
> I am quite new to sphinx I try to figuring out autodocumenting my
> Python code with it. I have setup a test-project [1] to play around
> with some settings.
>
> It seams like that autodoc ignores py-files that start with an
> underline; e.g. "_mypackage.py". I looked into the docu [2] but
> couldn't find a setting to explain/modify that behavior.

By default, private members are not documented.

If you're generating this documentation using 'sphinx-apidoc', you want to pass
the '--private ' / '-P' option [1]

If you are manually writing pages that use 'sphinx.ext.autodoc' directives,
then you can enable documentation of private members by add the 'private-
members' option [1] to each directive or by adding ':meta public:' to the
doctext of private classes, functions and variables that you wish to document.
You can also configure this behavior globally using the
'autodoc_default_options' flag [2].

Hope this helps,
Stephen

[1] https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html#cmdoption-sphinx-apidoc-P
[2] https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-option-automodule-private-members
[3] https://stackoverflow.com/a/44638788/613428
Reply all
Reply to author
Forward
0 new messages