RNA
RNA

Reputation: 153621

cross-refence link to a function/class in a different submodule

As a simple example, in the following code of 2 submodules (a.py and b.py in the same directory). The link to the same submodule function :func:`hook` works but not the link cross-referencing to a different moduel, ie, :func:`foo`. I also tried the syntax of :func:`.a.foo` - still does not work. How can I cross reference to a.foo()?

# script a.py
def foo():
    '''foo func'''

# script b.py
def hook():
    '''hook func'''

def spam():
    '''spam func.
    :func:`foo`
    :func:`hook`
'''

Upvotes: 2

Views: 317

Answers (1)

Sergey Vasilyev
Sergey Vasilyev

Reputation: 4189

As described in the docs:

Normally, names in these roles are searched first without any further qualification, then with the current module name prepended, then with the current module and class name (if any) prepended. If you prefix the name with a dot, this order is reversed.

In that case, :func:`.a.foo` means an object named a inside of the module b. It will look for b.a.foo function.

You should try :func:`..a.foo`, which will point to b..a.foo, or just a.foo (cannot check that locally now, sorry; but I remember I was using that syntax before).

But note, that a.py & b.py should be the modules, i.e. importable under their name. If they are just the scripts, and located not in a package (no __init__.py files up to the root of the project), there is no way to cross-reference with these roles.

You can try to use :any: role — :any:`foo` — and hope that it will find the object in the general index of the described objects.

Upvotes: 1

Related Questions