SmCaterpillar
SmCaterpillar

Reputation: 7020

Sphinx problems with cross-referencing of python functions

i have some problems with cross-referencing of functions in Sphinx. As long as I have only a single module, things like :func:`myfunc` work properly and I can click on the link to reach the referenced function.

Yet, adding more modules destroys the link and I can no longer click on it. The only way to work around that is to list the complete name of the function: :func:`mymodule.mysubmodule.MyClass.myfunc`. This is a bit annoying, especially because the whole name also shows up in the html page.

Is there a way to shorten the name of the link at least in the html documentation? I.e. that you only read myfunc instead of mymodule.mysubmodule.MyClass.myfunc?

Thanks!

Upvotes: 1

Views: 173

Answers (1)

fjarri
fjarri

Reputation: 9726

There are two things will probably find useful:

  • If your current module (set with .. currentmodule::) coincides with the module of the link, you do not have to specify it explicitly. Also you can reference one of the class methods from the docstring of another. From the doc:

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.

  • If you prefix the full name with ~, like :func:`~mymodule.mysubmodule.MyClass.myfunc`, HTML will only contain the last part.

Upvotes: 3

Related Questions