Krzysztof Słowiński
Krzysztof Słowiński

Reputation: 7207

Include specific imported functions in sphinx documentation

Let's say that my_module has the following __init__.py:

from my_module.misc import f2

def f1(p1,p2):
    """
    My f1 function.

    :param p1: First parameter.
    :param p2: Second parameter.
    :return: Returned value.
    """
    return p1 + p2

Where the misc.py contains the following function:

def f2(p1,p2):
    """
    My f2 function.

    :param p1: First parameter.
    :param p2: Second parameter.
    :return: Returned value.
    """
    return p1 - p2

I am documenting my_module using sphinx with the following approach and f2 is not appearing in the result, is there a way to specify that it should be included?

my_module
---------

.. automodule:: my_module
   :members:
   :undoc-members:

Upvotes: 2

Views: 595

Answers (1)

mzjn
mzjn

Reputation: 50947

It works if you add an __all__ list in __init__.py.

from my_module.misc import f2

__all__ = ["f1", "f2"]

def f1(p1,p2):
    """
    My f1 function.

    :param p1: First parameter.
    :param p2: Second parameter.
    :return: Returned value.
    """
    return p1 + p2

From the Sphinx documentation:

For modules, __all__ will be respected when looking for members unless you give the ignore-module-all flag option. Without ignore-module-all, the order of the members will also be the order in __all__.

Upvotes: 1

Related Questions