Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make imported memebrs link to their documentation. #411

Open
ShaiAvr opened this issue Nov 7, 2023 · 3 comments
Open

Make imported memebrs link to their documentation. #411

ShaiAvr opened this issue Nov 7, 2023 · 3 comments

Comments

@ShaiAvr
Copy link

ShaiAvr commented Nov 7, 2023

I am new to sphinx and autoapi so I may be missing something, but I searched the documentation and the internet and couldn't find a solution to my problem. I have a foo package which has a bar module and in it there is a Bar class. The Bar class is central to my library, so I decided to make an import shortcut for it. Inside the __init__.py file of the foo package I have the code:

from foo.bar import Bar

__all__ = ["Bar"]

So the end user can use from foo import Bar instead of the more verbose from foo.bar import Bar. Since I declared Bar in the __all__ variable, it gets picked up by autoapi and documented in the generated page for the foo package. There is also a page for the foo.bar module which contains the full docstring of the class. The problem is that I can't get the Bar class in the foo page to link to the documentation of Bar on the foo.bar page.

If I have the "imported-members" option in conf.py, the docstring of the Bar class is displayed in both the foo and foo.bar pages with no link between them. This is an unnecessary duplication and it makes the user think that there are two Bar symbols without explaining that one is just an alias for the other. If I disable the "imported-members" option, then the docstring only appears in the foo.bar page and on the foo page, Bar is listed in the package's contents, but that's it. It doesn't link to anything. So the user knows that foo.Bar is an alias, but he doesn't know to what. I'd like the Bar in the foo page to link to the full docstring in the foo.bar page, but I couldn't figure out how to accomplish that.

Any ideas?

@f-fuchs
Copy link

f-fuchs commented Dec 11, 2023

Hey,

we have the same problem. Did u find a solution?

@AWhetter
Copy link
Collaborator

AWhetter commented Feb 18, 2024

Sphinx 4 introduced a :canonical: option to some of the directives (https://www.sphinx-doc.org/en/master/usage/domains/python.html#directive-option-py-class-canonical). We should make use of this in the templates.

@nfelt14
Copy link

nfelt14 commented Apr 6, 2024

I am running into the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants