Skip to content

Commit 2d70631

Browse files
committed
intersphinx xref physical types
Signed-off-by: Nathaniel Starkman (@nstarman) <[email protected]>
1 parent 0e35fd0 commit 2d70631

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ install_requires =
2828
sphinx-automodapi
2929
sphinx-gallery
3030
pillow
31+
astropy
3132

3233
[options.package_data]
3334
sphinx_astropy = local/*

sphinx_astropy/conf/v1.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,40 @@ def check_sphinx_version(expected_version):
8888

8989
suppress_warnings = ['app.add_directive', ]
9090

91+
# -- NumpyDoc X-Ref ------------------------
92+
93+
# Whether to create cross-references for the parameter types in the
94+
# Parameters, Other Parameters, Returns and Yields sections of the docstring.
95+
# Should be set = True in packages manually! included here as reference.
96+
# numpydoc_xref_param_type = False
97+
98+
# Words not to cross-reference. Most likely, these are common words used in
99+
# parameter type descriptions that may be confused for classes of the same
100+
# name. This can be overwritten or modified in packages and is provided here for
101+
# convenience.
102+
numpydoc_xref_ignore = {
103+
'type', 'optional', 'default', 'or', 'of', 'method', 'instance', "like",
104+
"class", 'subclass', "keyword-only", "default", "thereof"
105+
}
106+
107+
# Mappings to fully qualified paths (or correct ReST references) for the
108+
# aliases/shortcuts used when specifying the types of parameters.
109+
# Numpy provides some defaults
110+
# https://github.com/numpy/numpydoc/blob/b352cd7635f2ea7748722f410a31f937d92545cc/numpydoc/xref.py#L62-L94
111+
# numpydoc_xref_aliases = {}
112+
113+
# TODO! refactor if #11678 is implemented
114+
from astropy.units.physical import _units_and_physical_types
115+
numpydoc_xref_aliases_astropy_physical_type = {}
116+
for _, ptypes in _units_and_physical_types:
117+
ptypes = {ptypes} if isinstance(ptypes, str) else ptypes
118+
for ptype in ptypes:
119+
key = f"'{ptype}'"
120+
val = f":ref:`:ref: '{ptype}' <astropy:{ptype}>`" # <= intersphinxed.
121+
numpydoc_xref_aliases_astropy_physical_type[key] = val
122+
123+
del ptypes, key, val
124+
91125
# -- Project information ------------------------------------------------------
92126

93127
# There are two options for replacing |today|: either, you set today to some

0 commit comments

Comments
 (0)