|
11 | 11 |
|
12 | 12 | import os
|
13 | 13 | import warnings
|
| 14 | +from collections import ChainMap |
14 | 15 |
|
15 | 16 | from os import path
|
16 | 17 |
|
17 | 18 | import sphinx
|
18 | 19 | from distutils.version import LooseVersion
|
19 | 20 |
|
| 21 | +try: |
| 22 | + import astropy |
| 23 | +except ImportError: |
| 24 | + ASTROPY_INSTALLED = False |
| 25 | +else: |
| 26 | + ASTROPY_INSTALLED = True |
| 27 | + |
| 28 | + from astropy.utils import minversion |
| 29 | + |
20 | 30 |
|
21 | 31 | # -- General configuration ----------------------------------------------------
|
22 | 32 |
|
@@ -88,6 +98,76 @@ def check_sphinx_version(expected_version):
|
88 | 98 |
|
89 | 99 | suppress_warnings = ['app.add_directive', ]
|
90 | 100 |
|
| 101 | +# -- NumpyDoc X-Ref ------------------------ |
| 102 | + |
| 103 | +# Whether to create cross-references for the parameter types in the |
| 104 | +# Parameters, Other Parameters, Returns and Yields sections of the docstring. |
| 105 | +# Should be set = True in packages manually! included here as reference. |
| 106 | +# numpydoc_xref_param_type = False |
| 107 | + |
| 108 | +# Words not to cross-reference. Most likely, these are common words used in |
| 109 | +# parameter type descriptions that may be confused for classes of the same |
| 110 | +# name. This can be overwritten or modified in packages and is provided here for |
| 111 | +# convenience. |
| 112 | +numpydoc_xref_ignore = {"or", "of", "thereof", |
| 113 | + "default", "optional", "keyword-only", |
| 114 | + "instance", "type", "class", "subclass", "method"} |
| 115 | + |
| 116 | +# Mappings to fully qualified paths (or correct ReST references) for the |
| 117 | +# aliases/shortcuts used when specifying the types of parameters. |
| 118 | +# Numpy provides some defaults |
| 119 | +# https://github.com/numpy/numpydoc/blob/b352cd7635f2ea7748722f410a31f937d92545cc/numpydoc/xref.py#L62-L94 |
| 120 | +numpydoc_xref_aliases = { |
| 121 | + # Python terms |
| 122 | + "function": ":term:`python:function`", |
| 123 | + "iterator": ":term:`python:iterator`", |
| 124 | + "mapping": ":term:`python:mapping`", |
| 125 | +} |
| 126 | + |
| 127 | +# Aliases to Astropy's glossary. In packages these can be turned on with |
| 128 | +# ``numpydoc_xref_aliases.update(numpydoc_xref_aliases_astropy_glossary)`` |
| 129 | +# (if astropy is in the intersphinx mapping). |
| 130 | +numpydoc_xref_aliases_astropy_glossary = {} # works even if no Astropy |
| 131 | +if ASTROPY_INSTALLED and minversion(astropy, "4.3"): |
| 132 | + numpydoc_xref_aliases_astropy_glossary = { |
| 133 | + # general |
| 134 | + "-like": ":term:`astropy:-like`", |
| 135 | + # coordinates |
| 136 | + "angle-like": ":term:`astropy:angle-like`", |
| 137 | + "coordinate-like": ":term:`astropy:coordinate-like`", |
| 138 | + "frame-like": ":term:`astropy:frame-like`", |
| 139 | + # units |
| 140 | + "unit-like": ":term:`astropy:unit-like`", |
| 141 | + "quantity-like": ":term:`astropy:quantity-like`", |
| 142 | + # table |
| 143 | + "table-like": ":term:`astropy:table-like`", |
| 144 | + # time |
| 145 | + "time-like": ":term:`astropy:time-like`", |
| 146 | + } |
| 147 | + |
| 148 | +# Aliases to Astropy's physical types. In packages these can be turned on with |
| 149 | +# ``numpydoc_xref_aliases.update(numpydoc_xref_aliases_astropy_physical_type)`` |
| 150 | +# (if astropy is in the intersphinx mapping). |
| 151 | +numpydoc_xref_aliases_astropy_physical_type = {} # works even if no astropy |
| 152 | +if ASTROPY_INSTALLED and minversion(astropy, "4.3"): |
| 153 | + |
| 154 | + from astropy.units.physical import _name_physical_mapping |
| 155 | + for ptype in _name_physical_mapping.keys(): |
| 156 | + val = f":ref:`:ref: '{ptype}' <astropy:{ptype}>`" # <= intersphinxed |
| 157 | + numpydoc_xref_aliases_astropy_physical_type[f"'{ptype}'"] = val |
| 158 | + |
| 159 | + del ptype, val, _name_physical_mapping # cleanup namespace |
| 160 | + |
| 161 | + |
| 162 | +# Convenient collection of all of astropy's options for numpydoc xref. |
| 163 | +# In packages all the astropy additions can be turned on with |
| 164 | +# ``numpydoc_xref_aliases.update(numpydoc_xref_astropy_aliases)`` |
| 165 | +# (if astropy is in the intersphinx mapping). |
| 166 | +numpydoc_xref_astropy_aliases = ChainMap( # important at the top |
| 167 | + numpydoc_xref_aliases_astropy_glossary, |
| 168 | + numpydoc_xref_aliases_astropy_physical_type |
| 169 | +) |
| 170 | + |
91 | 171 | # -- Project information ------------------------------------------------------
|
92 | 172 |
|
93 | 173 | # There are two options for replacing |today|: either, you set today to some
|
|
0 commit comments