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
Resolve intersphinx to astropy as current build #11690
Conversation
👋 Thank you for your draft pull request! Do you know that you can use |
a6028b2
to
b16d3aa
Compare
@@ -1035,7 +1035,7 @@ def separation(self, other): | |||
not give the same answer in this case. | |||
|
|||
For more on how to use this (and related) functionality, see the | |||
examples in :doc:`/coordinates/matchsep`. | |||
examples in :doc:`astropy:/coordinates/matchsep`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been following the various conversation on Sphinx xref and just by looking at this diff, I don't understand why this is needed in the core repo. Why not use the built-in Sphinx :ref:
again? What is an example use case where this would benefit affiliated package? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use the built-in Sphinx :ref: again?
The link is to a :doc:
, not a specific section, so :ref:
can't be used. Perhaps the link could be changed entirely, but for page references :doc:
is the Sphinx built-in.
What is an example use case where this would benefit affiliated package?
In this case, for subclassing SkyCoord. Both :doc:
and :ref:
are not inter-sphinxed automatically, so any link in the SkyCoord subclass can break when building the docs (if warnings -> errors). This PR enables astropy to set up internal links as if they were intersphinx links, but have them be interpreted as internal links. Affiliate packages would see these links as intersphinx links. This is quite similar to the astropy-dev
label, where Astropy sees it as internal (if it's the dev build), while affiliate packages see it as an intersphinx.
I hope this PR will enable astropy to provide more links in docstrings and affiliate packages won't have to worry about a thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot find any documentation of :doc:
in the official Sphinx doc (which is kinda ironic), can you please link me to its doc? Thanks!
As for :ref:
intersphinx, I haven't seen a problem downstream where I use ~astropy.coordinates.SkyCoord
and so on. I did see a problem when the doc here refers to simply SkyCoord
but the fix is to mention the full namespace in core API doc.
As for referring to page vs section, I don't see the point of the former. Why not have a :ref:
at the top of the page and then use :ref:
?
Sorry if all these had been discussed before. If so, please point me to the old discussions. Thanks for your patience!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I do remember discussion quite a while ago that docstrings should use proper http links so that people who see them in an interactive session can actually follow them....
But in that respect the scheme with :doc:
is better than a :ref:
- with that, the user truly has no hope to find this except by going to the docstring online. Also, the :doc:astrop
seems a nice clear marker. Plus, this scheme has the advantage over an http
link that we'll notice breakage sooner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question: is the /
in front of /coordinates
necessary? Or does it try to find the link in the local environment of the SkyCoord
docstring rendering otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation. It makes sense now. The whole sphinx stuff remains a bit of black magic to me... Not sure that expanding the changelog will be needed; if anything, we'd need some docs for affiliate package maintainers, but not clear how they would find that... So, let's just stick with fixing a possible bug with subclassing SkyCoord
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing a project to refer to itself via intersphinx seems generically useful for protecting from docstring inheritance. I wish sphinx did this automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I think I get it now. I was thinking about :ref:
in docstring pointing to another API, but here you are talking about human doc.
Is this PR standalone or it depends on the other PR you opened over at sphinx-astropy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is standalone in that it works and does the docs stuff independently.
It's definitely part of a larger push to make intersphinx and particularly xref useful for downstream packages. In some respects, this PR is the foundation on which future PRs can be built since all the downstream packages need astropy xref links to be intersphinxed, but without this PR, those links wouldn't work inside of Astropy. Now sphinx-astropy will work equally well for both Astropy and downstream packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks all good, now I understand it. Perhaps still worth elaborating a bit in the changelog entry? Though not a blocker, so feel free to ignore.
14896cc
to
5cb496c
Compare
@pllim - what do you think, does it make sense to do this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks on the change log but I'll leave it to your judgement which suggested changes make sense to you.
Probably also want to add a comment on the affected code about the Sphinx issue you raised. If this is implemented upstream, then we can remove it in the future.
I would still like Madison to have a look as they implemented the original function you are adding on to.
Thanks!
Agreed. I've added a little note on lines 375-377
👍 |
How many other places in the astropy docs use IIUC though that wouldn't solve the problem you're trying to solve anyways. But then why single out I'm 👍 to solving this problem, and don't have any objections to this approach. But ISTM like a deeper problem related to Sphinx... |
Agreed on a more general solution. Though there may not be that many other instances: I think before we really tried hard to avoid having sphinx links in docstrings, since those are not useful when doing interactive work; although hard-coded URLs are also far from ideal.... |
I have in the past toyed with the idea of having a packaging hook that would go through and render all sphinx links in docstrings to URLs. This mapping would in turn be used by an extension to IPython's help system to replace the links. I have a little utility function called |
Unfortunately, no that wouldn't solve this problem. Wish it did.
Necessity as the mother of invention. I just first encountered this in SkyCoord. Doing a search for
Hmm. good point. I'll add something to the developer docs.
Agreed that an upstream fix would be nice. I've raised an issue at sphinx-doc/sphinx#9169. If that is implemented then the docstring changes here would be kept the same and only the intersphinx override magic in |
Ok. @embray I think I got all |
This enables astropy to use astropy intersphinx links and correctly resolve them to the version being built. Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Co-authored by @pllim Co-authored-by: P. L. Lim <2090236+pllim@users.noreply.github.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
979ae64
to
f7d2f81
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nstarman - I think the case has gotten stronger, and thanks for sticking with it! Only one real comment, about the location of the new instructions.
@@ -0,0 +1,3 @@ | |||
Sphinx RST links in ``SkyCoord`` now use intersphinx for downstream packages' convenience. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it all through astropy now? Or is SkyCoord
still the only thing that could be subclassed and thus be wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's now all over astropy. I'm moving the note up to the top level. I've contributed a number of such fragments, all about xref, docstrings, and the documentation. Perhaps there should be a specific category / folder for such changelog fragmets, e.g. documentation/
. @saimn how feasible is this with towncrier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this would need a changelog to begin with. And as a rule of thumb, the changelog doesn't have any links. The links tend to broke on the many year timescale, and while SkyCoord is expected not to be one of those, the blanket rule of no links works better than trying to maintain a list of OK and not OK types of links.
docs/development/docguide.rst
Outdated
+ cross-reference links (``:ref:``, ``:doc:``, etc.), **including internal | ||
Astropy links**, should use the `intersphinx format | ||
<https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html>`_. | ||
Note that in Astropy these internal links are to the current build, while |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not super helpful, maybe add an example? Also, I thought this was required only for the docstrings, not for "all documentation" (which the bullet is about), so I think you need it to one of the following bullet points (maybe the numpydoc
one? Or just its own bullet point "References in docstrings ..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! and noted 'astropy-dev' links to the dev version of astropy.
@mhvk Agreed on both points. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, looks all good now. Thanks!
Though I'm not sure what's wrong with readthedocs; did the docs pass locally and did you check the new addition in the dev docs?
Anyway, approving under the assumption that's a false positive (I had a failure recently too that I did not understand), and that the changelog fragment is located OK.
Yes to the above. Let me check again the RTD is unrelated. |
RTD warnings might be related. I don't see this in
|
Thanks @pllim. It was the example code I added in the news fragment! I edited that after doing a local build. But I put the links in an in-line code block, so I didn't think they would get picked up. |
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
7fa7ed2
to
470d1ba
Compare
RTD is green now but I would still like @embray to approve if they are okay with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having to put astropy:
everywhere is quite a mess, and I think people (by which I mean me) will definitely forget to do this. But it's also exactly what I suggested you do, so I can't complain ;)
It's an unfortunate Sphinx limitation that doesn't come up very often, but for something like Astropy it is a real problem. Thanks for opening the issue against Sphinx.
@@ -64,7 +64,7 @@ class TETE(BaseRADecFrame): | |||
with local apparent sidereal time to calculate the apparent (TIRS) hour angle. | |||
|
|||
For more background on TETE, see the references provided in the | |||
:ref:`astropy-coordinates-seealso` section of the documentation. | |||
:ref:`astropy:astropy-coordinates-seealso` section of the documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These astropy:astropy
references are unfortunate. I won't ask you to change them, but I wonder why those labels contained "astropy-" in the first place. Seems redundant. We can deal with that in a follow-up, if at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I didn't like those either. And they're now doubly redundant.
This enables astropy to use astropy intersphinx links and correctly resolve them to the version being built.
This is implemented in SkyCoord so that links to the docs works in affiliate packages.
Part of #11555
Request Review: @mhvk @adrn @pllim @embray
Signed-off-by: Nathaniel Starkman (@nstarman) nstarkman@protonmail.com