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

Resolve intersphinx to astropy as current build #11690

Merged
merged 6 commits into from May 21, 2021

Conversation

nstarman
Copy link
Member

@nstarman nstarman commented May 4, 2021

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

@github-actions
Copy link

github-actions bot commented May 4, 2021

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@nstarman
Copy link
Member Author

nstarman commented May 4, 2021

Success! the links in SkyCoord are still live and refer to the current build.

Screen Shot 2021-05-03 at 21 37 45

@nstarman nstarman marked this pull request as ready for review May 4, 2021 01:38
docs/conf.py Outdated Show resolved Hide resolved
@@ -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`.
Copy link
Member

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!

Copy link
Member Author

@nstarman nstarman May 4, 2021

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.

Copy link
Member

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!

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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?

Copy link
Member Author

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.

@pllim pllim added this to the v5.0 milestone May 4, 2021
Copy link
Contributor

@mhvk mhvk left a 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.

docs/changes/coordinates/11690.other.rst Outdated Show resolved Hide resolved
@mhvk
Copy link
Contributor

mhvk commented May 5, 2021

@pllim - what do you think, does it make sense to do this?

Copy link
Member

@pllim pllim left a 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!

docs/changes/coordinates/11690.other.rst Outdated Show resolved Hide resolved
docs/changes/coordinates/11690.other.rst Outdated Show resolved Hide resolved
docs/changes/coordinates/11690.other.rst Outdated Show resolved Hide resolved
@pllim pllim requested a review from embray May 5, 2021 14:13
@nstarman
Copy link
Member Author

nstarman commented May 5, 2021

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.

Agreed. I've added a little note on lines 375-377

I would still like Madison to have a look as they implemented the original function you are adding on to.

👍

@embray
Copy link
Member

embray commented May 17, 2021

How many other places in the astropy docs use :doc: and is there a reason we couldn't just replace them with normal :ref: links?

IIUC though that wouldn't solve the problem you're trying to solve anyways.

But then why single out SkyCoord? In principle there are tons of other classes containing docstrings that link to other pages in the astropy docs. And this new special feature isn't really documented anywhere, so how would remind developers writing new docstrings that it should be used?

I'm 👍 to solving this problem, and don't have any objections to this approach. But ISTM like a deeper problem related to Sphinx...

@mhvk
Copy link
Contributor

mhvk commented May 17, 2021

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....

@embray
Copy link
Member

embray commented May 17, 2021

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 desphinxify which strips some other Sphinx markup from docstrings and makes them look a bit nicer, but it doesn't handle links yet.

@nstarman
Copy link
Member Author

How many other places in the astropy docs use :doc: and is there a reason we couldn't just replace them with normal :ref: links?
IIUC though that wouldn't solve the problem you're trying to solve anyways.

Unfortunately, no that wouldn't solve this problem. Wish it did.

But then why single out SkyCoord? In principle there are tons of other classes containing docstrings that link to other pages in the astropy docs.

Necessity as the mother of invention. I just first encountered this in SkyCoord. Doing a search for :doc:, SkyCoord is currently the only docstring that has an astropy doc link. There are a number of :ref: links to specific sections. I'll attend to those shortly.

And this new special feature isn't really documented anywhere, so how would remind developers writing new docstrings that it should be used?

Hmm. good point. I'll add something to the developer docs.

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 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 conf.py will be deprecated.

@nstarman
Copy link
Member Author

Ok. @embray I think I got all :ref: in the docstrings and made them "intersphinx". I didn't do the ones in the docs as those cannot be inherited. Likewise, I added to the dev docs saying that all links in the docstrings should be made intersphinxed, including Astropy's. It would be nice to have some test for this, but IDK how one would test in the core package a change intended for affiliate packages.
@mhvk, this is a somewhat large diff from what you approved, so I'm re-requesting a review.

nstarman and others added 4 commits May 17, 2021 18:01
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>
Copy link
Contributor

@mhvk mhvk left a 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.
Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's easy to do but until now the policy has been that we do not mention documentation changes. Exceptions are possible such as for big changes like you did but I'm not sure that justifies a new category. "other" seems fine to me. @pllim @bsipocz - Thoughts ?

Copy link
Member

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.

+ 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
Copy link
Contributor

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 ..."

Copy link
Member Author

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.

@nstarman
Copy link
Member Author

nstarman commented May 18, 2021

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....

@mhvk Agreed on both points.
I do think that sphinx links in docstrings can be useful for providing a note on where to find further reading and examples. Those don't detract from looking at the docstring in an interactive environment. I like @embray's idea of hot swapping for URLs. If this were done on compile so the PIP version had URLs, Jupyter Lab makes the links live!

Copy link
Contributor

@mhvk mhvk left a 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.

@nstarman
Copy link
Member Author

Yes to the above. Let me check again the RTD is unrelated.

@pllim
Copy link
Member

pllim commented May 19, 2021

RTD warnings might be related. I don't see this in main.

WARNING: :533: (WARNING/2) Inline literal start-string without end-string.
...
<unknown>:533: WARNING: undefined label: link
<unknown>:533: WARNING: undefined label: astropy:link

@nstarman
Copy link
Member Author

nstarman commented May 19, 2021

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>
@pllim
Copy link
Member

pllim commented May 19, 2021

RTD is green now but I would still like @embray to approve if they are okay with this.

Copy link
Member

@embray embray left a 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.
Copy link
Member

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.

Copy link
Member Author

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.

@embray embray merged commit e183e39 into astropy:main May 21, 2021
@nstarman nstarman deleted the coord_SkyCoord_links branch May 21, 2021 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants