15
15
16
16
from os import path
17
17
18
- import astropy
19
18
import sphinx
20
19
from distutils .version import LooseVersion
21
20
21
+ try :
22
+ import astropy
23
+ except ImportError :
24
+ ASTROPY_INSTALLED = False
25
+ else :
26
+ ASTROPY_INSTALLED = True
27
+
22
28
23
29
# -- General configuration ----------------------------------------------------
24
30
@@ -102,8 +108,8 @@ def check_sphinx_version(expected_version):
102
108
# name. This can be overwritten or modified in packages and is provided here for
103
109
# convenience.
104
110
numpydoc_xref_ignore = {
105
- ' type' , ' optional' , ' default' , 'or' , 'of' , ' method' , 'instance' , "like " ,
106
- "class" , ' subclass' , "keyword-only" , "default" , "thereof"
111
+ " type" , " optional" , " default" , "or" , "of" , " method" , "instance " ,
112
+ "class" , " subclass" , "keyword-only" , "default" , "thereof" ,
107
113
}
108
114
109
115
# Mappings to fully qualified paths (or correct ReST references) for the
@@ -120,14 +126,11 @@ def check_sphinx_version(expected_version):
120
126
# Aliases to Astropy's glossary. In packages these can be turned on with
121
127
# ``numpydoc_xref_aliases.update(numpydoc_xref_aliases_astropy_glossary)``
122
128
# (if astropy is in the intersphinx mapping).
123
- numpydoc_xref_aliases_astropy_glossary = {} # works even if older astropy
124
- if float (astropy .__version__ [:3 ]) >= 4.3 :
129
+ numpydoc_xref_aliases_astropy_glossary = {} # works even if older Astropy
130
+ if ASTROPY_INSTALLED and float (astropy .__version__ [:3 ]) >= 4.3 :
125
131
numpydoc_xref_aliases_astropy_glossary = {
126
132
# general
127
133
"-like" : ":term:`astropy:-like`" ,
128
- # "number": ":term:`number`",
129
- # "writable": ":term:`writable file-like object`",
130
- # "readable": ":term:`readable file-like object`",
131
134
# coordinates
132
135
"angle-like" : ":term:`astropy:angle-like`" ,
133
136
"coordinate-like" : ":term:`astropy:coordinate-like`" ,
@@ -145,18 +148,14 @@ def check_sphinx_version(expected_version):
145
148
# ``numpydoc_xref_aliases.update(numpydoc_xref_aliases_astropy_physical_type)``
146
149
# (if astropy is in the intersphinx mapping).
147
150
numpydoc_xref_aliases_astropy_physical_type = {} # works even if older astropy
148
- if float (astropy .__version__ [:3 ]) >= 4.3 :
149
-
150
- # TODO! refactor if #11678 is implemented
151
- from astropy .units .physical import _units_and_physical_types
152
- for _ , ptypes in _units_and_physical_types :
153
- ptypes = {ptypes } if isinstance (ptypes , str ) else ptypes
154
- for ptype in ptypes :
155
- key = f"'{ ptype } '"
156
- val = f":ref:`:ref: '{ ptype } ' <astropy:{ ptype } >`" # <= intersphinxed.
157
- numpydoc_xref_aliases_astropy_physical_type [key ] = val
158
-
159
- del ptypes , key , val , _units_and_physical_types
151
+ if ASTROPY_INSTALLED and float (astropy .__version__ [:3 ]) >= 4.3 :
152
+
153
+ from astropy .units .physical import _name_physical_mapping
154
+ for ptype in _name_physical_mapping .keys ():
155
+ val = f":ref:`:ref: '{ ptype } ' <astropy:{ ptype } >`" # <= intersphinxed
156
+ numpydoc_xref_aliases_astropy_physical_type [f"'{ ptype } '" ] = val
157
+
158
+ del ptype , val , _name_physical_mapping # cleanup namespace
160
159
161
160
162
161
# Convenient collection of all of astropy's options for numpydoc xref.
0 commit comments