Skip to content

Commit

Permalink
Resolve intersphinx to astropy as current build
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nstarman committed May 4, 2021
1 parent 0860b70 commit b16d3aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
12 changes: 6 additions & 6 deletions astropy/coordinates/sky_coordinate.py
Expand Up @@ -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`.
Parameters
----------
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def separation_3d(self, other):
and another.
For more on how to use this (and related) functionality, see the
examples in :doc:`/coordinates/matchsep`.
examples in :doc:`astropy:/coordinates/matchsep`.
Parameters
----------
Expand Down Expand Up @@ -1259,7 +1259,7 @@ def match_to_catalog_sky(self, catalogcoord, nthneighbor=1):
catalog coordinates.
For more on how to use this (and related) functionality, see the
examples in :doc:`/coordinates/matchsep`.
examples in :doc:`astropy:/coordinates/matchsep`.
Parameters
----------
Expand Down Expand Up @@ -1324,7 +1324,7 @@ def match_to_catalog_3d(self, catalogcoord, nthneighbor=1):
``catalogcoord`` object.
For more on how to use this (and related) functionality, see the
examples in :doc:`/coordinates/matchsep`.
examples in :doc:`astropy:/coordinates/matchsep`.
Parameters
----------
Expand Down Expand Up @@ -1389,7 +1389,7 @@ def search_around_sky(self, searcharoundcoords, seplimit):
`~astropy.coordinates.SkyCoord.separation`.
For more on how to use this (and related) functionality, see the
examples in :doc:`/coordinates/matchsep`.
examples in :doc:`astropy:/coordinates/matchsep`.
Parameters
----------
Expand Down Expand Up @@ -1448,7 +1448,7 @@ def search_around_3d(self, searcharoundcoords, distlimit):
`~astropy.coordinates.SkyCoord.separation_3d`.
For more on how to use this (and related) functionality, see the
examples in :doc:`/coordinates/matchsep`.
examples in :doc:`astropy:/coordinates/matchsep`.
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions docs/changes/coordinates/11690.other.rst
@@ -0,0 +1 @@
SkyCoord links now use intersphinx links to to work in affiliate packages.
33 changes: 25 additions & 8 deletions docs/conf.py
Expand Up @@ -355,22 +355,39 @@ def rstjinja(app, docname, source):
source[0] = rendered


def resolve_astropy_dev_reference(app, env, node, contnode):
def resolve_astropy_and_dev_reference(app, env, node, contnode):
"""
Reference targets beginning with ``astropy-dev:`` are a special case.
Reference targets for ``astropy:`` and ``astropy-dev:`` are special cases.
If we are building the development docs it is a local ref targetting the
Documentation links in astropy can be set up as intersphinx links so that
affiliate packages do not have to override the docstrings when building
the docs.
If we are building the development docs it is a local ref targeting the
label ``astropy-dev:<label>``, but for stable docs it should be an
intersphinx resolution to the development docs.
See https://github.com/astropy/astropy/issues/11366
"""

reftarget = node.get('reftarget')
if dev and reftarget is not None and reftarget.startswith('astropy-dev:'):
# should the node be processed?
reftarget = node.get('reftarget') # str or None
if str(reftarget).startswith('astropy:'):
process, replace = True, 'astropy:'
elif dev and str(reftarget).startswith('astropy-dev:'):
process, replace = True, 'astropy-dev:'
else:
process, replace = False, ''

# make link local
if process:
reftype = node.get('reftype')
refdoc = node.get('refdoc', app.env.docname)
reftarget = reftarget.split(':', 1)[1]
# convert astropy intersphinx targets to local links.
# there are a few types of intersphinx link patters, as described in
# https://docs.readthedocs.io/en/stable/guides/intersphinx.html
reftarget = reftarget.replace(replace, '')
if reftype == "doc": # also need to replace the doc link
node.replace_attr("reftarget", reftarget)
# Delegate to the ref node's original domain/target (typically :ref:)
try:
domain = app.env.domains[node['refdomain']]
Expand Down Expand Up @@ -401,5 +418,5 @@ def setup(app):
# Set this to higher priority than intersphinx; this way when building
# dev docs astropy-dev: targets will go to the local docs instead of the
# intersphinx mapping
app.connect("missing-reference", resolve_astropy_dev_reference,
app.connect("missing-reference", resolve_astropy_and_dev_reference,
priority=400)

0 comments on commit b16d3aa

Please sign in to comment.