The add_module_names
boolean is a general configuration setting in conf.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 by add_module_names = True
.
Two simple example files, bar.some_other_file.py
:
"""bar.some_other_file module docstring."""
def some_other_function():
"""some_other_function docstring."""
and _foo.some_file.py
:
"""_foo.some_file module docstring."""
def some_function(argument_example="a string"):
"""some_function docstring."""
Using the following .rst
to compare both cases:
_foo costum module name
-----------------------
.. automodule:: _foo.some_file
:members:
:undoc-members:
:exclude-members: some_function
.. autofunction:: some_function
.. py:function:: .some_function(argument_example="a string")
:noindex:
Example without any module name.
bar costum module name
----------------------
.. automodule:: bar.some_other_file
:members:
:undoc-members:
:exclude-members: some_other_function
.. autofunction:: some_other_function
.. py:function:: bar.some_other_file.some_function(argument_example="a string")
:noindex:
Example with a different qualified name.
Gives the following result:
