How can I change add_module_names
to False
for specific modules?
I have the following structure:
src/
/ _foo
some_file.py
/ bar
some_other_file.py
I would like that all functions documents with .. autofunction::
from the _foo
module to have the name of the module hidden, while all functions of the bar module display the name.
Is there a way for me to perform this configuration by module, or even individually for each function?
The
add_module_names
boolean is a general configuration setting inconf.py
. It reflects your project-wide choice to render module names with objects, it can't be changed for a specific module. An exception to the rule can be implemented but the workaround requires some extra writing.The solution is to explicitly declare the members you want using a domain directive, in this case
.. py:function::
. This lets you specify the signature and the fully qualified name - PEP 3155. The drawback is you won't be using an autodoc directive so you loose the automatic extraction of docstrings from your Python source code. Depending on where you decide to place.. py:function::
it may be necessary to use:noindex:
and:exclude-members:
in specific directives - usage shown in the example.Notice the last example still requires a leading
.
dot, otherwise Sphinx will prepend the fully qualified name as specified byadd_module_names = True
.Two simple example files,
bar.some_other_file.py
:and
_foo.some_file.py
:Using the following
.rst
to compare both cases:Gives the following result: