-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Show correct user-facing module paths in documentation stub pages #1826
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
Conversation
|
Thanks for doing this @kbarbary - I'd been hoping someone would take a crack at this! I'm definitely 👍 for this. For a few more specific items:
|
|
|
@eteq More specifics on the automodsumm failure I'm seeing: This works: But this does not: This is surprising to me because I thought that the latter is basically turned into the former during processing. When doing the latter, I get warnings like (and similar for other classes) |
|
@kbarbary - sorry I lost track of this, but I've done some investigation. I'm still puzzled, but I have some things for you to try. At one point I was seeing the same error as you, but it has since disappeared and I can no longer reproduce it on master. So perhaps try on master? Or Sphinx 1.2 (recently released), if you were using 1.1.3 before? Another thing that may be important: to get the behavior you want, you need a Also, I think you still want So the following worked for me (and gave the same output I expected from Does that work for you? |
|
@kbarbary - what is the status of this? It'd be great to have this working for |
|
@astrofrog Taking a look now. Sorry I've been putting this off... |
|
@eteq Still looking at this, but curious about your comment: I guess it isn't obvious, but this PR changes |
|
@eteq, this does indeed work for me (now on Sphinx 1.2, rebased on astropy master): (toctree directive not needed). However, this is confusing. As I noted, I put It might be good to have something like #1975 for automodsumm. |
|
I just added #2022, which does just as you suggest here, @kbarbary - it adds a |
|
@kbarbary - One thing I've figured out: at least for me, (still investigating why |
|
Ok, I'm still mystified as to why this happens. For some reason, Sphinx just refuses to acknowledge the I managed to hack together a work-around, though. See the PR kbarbary#3 I just issued against this branch. That actually forces sphinx's internal environment to do the same thing it does when |
Make it so that the stub pages generated with automodapi have the paths to the function or class that a user should use. For example, the Table class now appears as astropy.table.Table rather than astropy.table.table.Table.
This is necessary under the revised automodsumm to correctly link to already-created stub pages. It should be possible to use automodsumm with the `:classes-only:` option, but that doesn't seem to be working.
Using local names in autosummary fails to link to raw code with the current released version of the viewcode sphinx extension (Sphinx v1.1.3). This patched version fixes the problem. It can be removed once the problem is fixed in Sphinx proper (there is an issue open).
|
Rebased and included @eteq's hack-fix. I've kinda gotten lost as to what the status of this is. I built the docs and they look fine, with the exception that stuff like |
|
@kbarbary Thanks for implementing this ... I think it's really important that the API docs show the locations that users are supposed to use for imports. @astrofrog @eteq What remains to be done / checked before this can be merged? (I just went through gammapy fixing all sphinx links and am willing to help fix all the links in astropy and affiliated packages, but this PR should be merged first.) |
|
@cdeil @kbarbary - I finally managed to go through and do some spot-checks, and as far as I can tell, this is now good to go. I'll go ahead and just merge it manually because there's a minor conflict that isn't worth rebasing. Thanks again for all your work on this @kbarbary, and @cdeil, feel free to start digging through the huge pile of |
Only required merging two changes to extensions in conf.py Conflicts: astropy/sphinx/conf.py
|
I guess that this will warrant a what's new entry because it might break a lot of API URLs. I don't think we need to be backward-compatible, but |
|
Ah, good point @astrofrog - I updated the changelog but not what's new. Will add that now directly in master. |
|
Actually, I'm doing the what's new thing in #2147 because I just realized it requires making a new file. |
|
I think there's still a problem for (at least some) sub-packages that have an extra layer in the hierarchy. What needs to be done to changed so that these things show up at the location where users are supposed to import from? |
|
Let's try and figure the issue I just mentioned in a new issue: #2148 |
[ci skip]
…dsumm-paths Only required merging two changes to extensions in conf.py Conflicts: astropy/sphinx/conf.py
…dsumm-paths Only required merging two changes to extensions in conf.py Conflicts: astropy/sphinx/conf.py
Motivation
I've run into the problem recently that I point a user to an API documentation page, say
http://astropy.readthedocs.org/en/stable/api/astropy.stats.funcs.sigma_clip.html
to pick a random example, and the user sees the path to the function as being
astropy.stats.funcs.sigma_cliprather thanastropy.stats.sigma_clip. As a result, it is not entirely clear what is the correct way to import the function or class. This problem exists throughout the documentation: in most cases we import module objects into a higher-level namespace and intend for users to only use the higher-level namespace.What it does
This PR changes the automodsumm sphinx extension so that built stub pages have the API that users should use. It does this by using the
.. currentmodule::directive and then supplying the.. autosummary::directive with the local, rather than fully qualified object names. A built set of docs can be found here. See for instance http://www.hep.anl.gov/kbarbary/astropy-docs/api/astropy.stats.sigma_clip.htmlRelated changes
In conjunction, there are a few other necessary changes:
Include a patched version of the
viewcodeextension, as the current version in sphinx fails to link to code correctly under this usage of autosummary. The patch comes from this issue in the sphinx issue tracker: https://bitbucket.org/birkenfeld/sphinx/issue/623/ so hopefully it will be merged into Sphinx proper, at which point this patched version can be removed from astropy.I had to change an automodsumm table in the
convolution/kernels.rstdocumentation to an explicit autosummary table. It should be possible to simply dothere, but that wasn't working and I couldn't figure out why not. Help making that work would be appreciated.
Third, I noticed I missing
__all__in convolution/core.py. The omission has been resulting in AstropyUserWarning being included in the API docs for convolution, which was not intended.Remaining issues
There are some remaining issues before this PR is merged:
viewcodebug that isn't fixed by the patch... currentmodule::directives in the docs (which is what this does) may have unintended consequences, particularly if the directive is already used somewhere on the page and an.. automodsumm::or.. automodapi::directive is given mid-page. Fortunately the later is typically used at the bottom of the page, so this might not be a big issue.