12
12
try :
13
13
from sphinx_astropy .conf .v1 import * # noqa
14
14
except ImportError :
15
- print ('ERROR: Building the documentation for Gala requires the '
16
- 'sphinx-astropy package to be installed' )
15
+ print (
16
+ "ERROR: Building the documentation for Gala requires the "
17
+ "sphinx-astropy package to be installed"
18
+ )
17
19
sys .exit (1 )
18
20
19
21
# Get configuration information from setup.cfg
20
22
from configparser import ConfigParser
23
+
21
24
conf = ConfigParser ()
22
25
23
26
docs_root = pathlib .Path (__file__ ).parent .resolve ()
24
- conf .read ([str (docs_root / '..' / 'setup.cfg' )])
25
- setup_cfg = dict (conf .items ('metadata' ))
26
27
27
28
# -- General configuration ----------------------------------------------------
28
29
29
30
# By default, highlight as Python 3.
30
- highlight_language = ' python3'
31
+ highlight_language = " python3"
31
32
32
33
# List of patterns, relative to source directory, that match files and
33
34
# directories to ignore when looking for source files.
34
- exclude_patterns = [' _build' , ' **.ipynb_checkpoints' ]
35
+ exclude_patterns = [" _build" , " **.ipynb_checkpoints" ]
35
36
36
37
# Add any paths that contain templates here, relative to this directory.
37
- templates_path = [' _templates' ]
38
+ templates_path = [" _templates" ]
38
39
39
40
# The suffix(es) of source filenames.
40
41
# You can specify multiple suffix as a list of string:
41
42
# source_suffix = ['.rst', '.md']
42
- source_suffix = ' .rst'
43
+ source_suffix = " .rst"
43
44
44
45
# Don't show summaries of the members in each class along with the
45
46
# class' docstring
51
52
52
53
autosummary_generate = True
53
54
54
- automodapi_toctreedirnm = ' api'
55
+ automodapi_toctreedirnm = " api"
55
56
56
57
# The reST default role (used for this markup: `text`) to use for all
57
58
# documents. Set to the "smart" one.
58
- default_role = ' obj'
59
+ default_role = " obj"
59
60
60
61
# Class documentation should contain *both* the class docstring and
61
62
# the __init__ docstring
68
69
69
70
# intersphinx
70
71
intersphinx_mapping = {
71
- ' python' : (' https://docs.python.org/3/' , None ),
72
- ' numpy' : (' https://numpy.org/doc/stable/' , None ),
73
- ' scipy' : (' https://docs.scipy.org/doc/scipy/reference/' , None ),
74
- ' matplotlib' : (' https://matplotlib.org/' , None ),
75
- ' astropy' : (' https://docs.astropy.org/en/stable/' , None ),
76
- ' h5py' : (' https://docs.h5py.org/en/stable/' , None ),
77
- ' sympy' : (' https://docs.sympy.org/latest/' , None )
72
+ " python" : (" https://docs.python.org/3/" , None ),
73
+ " numpy" : (" https://numpy.org/doc/stable/" , None ),
74
+ " scipy" : (" https://docs.scipy.org/doc/scipy/reference/" , None ),
75
+ " matplotlib" : (" https://matplotlib.org/" , None ),
76
+ " astropy" : (" https://docs.astropy.org/en/stable/" , None ),
77
+ " h5py" : (" https://docs.h5py.org/en/stable/" , None ),
78
+ " sympy" : (" https://docs.sympy.org/latest/" , None ),
78
79
}
79
80
80
81
# Show / hide TODO blocks
83
84
# -- Project information ------------------------------------------------------
84
85
85
86
# This does not *have* to match the package name, but typically does
86
- project = setup_cfg ['name' ]
87
- author = setup_cfg ['author' ]
88
- copyright = '{0}, {1}' .format (
89
- datetime .datetime .now ().year , setup_cfg ['author' ])
87
+ project = "gala"
88
+ author = "Adrian Price-Whelan"
89
+ copyright = "{0}, {1}" .format (datetime .datetime .now ().year , author )
90
90
91
- package_name = ' gala'
91
+ package_name = " gala"
92
92
import_module (package_name )
93
93
package = sys .modules [package_name ]
94
94
95
95
from cmastro import cmaps
96
- plot_formats = [('png' , 200 ), ('pdf' , 200 )]
96
+
97
+ plot_formats = [("png" , 200 ), ("pdf" , 200 )]
97
98
plot_apply_rcparams = True
98
99
# NOTE: if you update these, also update docs/tutorials/nb_setup
99
100
plot_rcparams = {
100
- 'image.cmap' : 'cma:hesperia' ,
101
-
101
+ "image.cmap" : "cma:hesperia" ,
102
102
# Fonts:
103
- 'font.size' : 16 ,
104
- 'figure.titlesize' : 'x-large' ,
105
- 'axes.titlesize' : 'large' ,
106
- 'axes.labelsize' : 'large' ,
107
- 'xtick.labelsize' : 'medium' ,
108
- 'ytick.labelsize' : 'medium' ,
109
-
103
+ "font.size" : 16 ,
104
+ "figure.titlesize" : "x-large" ,
105
+ "axes.titlesize" : "large" ,
106
+ "axes.labelsize" : "large" ,
107
+ "xtick.labelsize" : "medium" ,
108
+ "ytick.labelsize" : "medium" ,
110
109
# Axes:
111
- 'axes.labelcolor' : 'k' ,
112
- 'axes.axisbelow' : True ,
113
-
110
+ "axes.labelcolor" : "k" ,
111
+ "axes.axisbelow" : True ,
114
112
# Ticks
115
- 'xtick.color' : '#333333' ,
116
- 'xtick.direction' : 'in' ,
117
- 'ytick.color' : '#333333' ,
118
- 'ytick.direction' : 'in' ,
119
- 'xtick.top' : True ,
120
- 'ytick.right' : True ,
121
-
122
- 'figure.dpi' : 300 ,
123
- 'savefig.dpi' : 300 ,
113
+ "xtick.color" : "#333333" ,
114
+ "xtick.direction" : "in" ,
115
+ "ytick.color" : "#333333" ,
116
+ "ytick.direction" : "in" ,
117
+ "xtick.top" : True ,
118
+ "ytick.right" : True ,
119
+ "figure.dpi" : 300 ,
120
+ "savefig.dpi" : 300 ,
124
121
}
125
122
plot_include_source = False
126
123
127
124
# The short X.Y version.
128
- version = package .__version__ .split ('-' , 1 )[0 ]
125
+ version = package .__version__ .split ("-" , 1 )[0 ]
129
126
# The full version, including alpha/beta/rc tags.
130
127
release = package .__version__
131
128
132
129
133
130
# -- Options for HTML output ---------------------------------------------------
134
131
135
- html_theme = ' pydata_sphinx_theme'
136
- html_logo = ' _static/Gala_Logo_RGB.png'
132
+ html_theme = " pydata_sphinx_theme"
133
+ html_logo = " _static/Gala_Logo_RGB.png"
137
134
138
135
html_theme_options = {
139
136
"logo" : {
140
- "image_light" : "Gala_Logo_RGB.png" ,
141
- "image_dark" : "Gala_Logo_RGB.png" ,
142
- },
137
+ "image_light" : "Gala_Logo_RGB.png" ,
138
+ "image_dark" : "Gala_Logo_RGB.png" ,
139
+ },
143
140
"icon_links" : [
144
141
{
145
142
"name" : "GitHub" ,
164
161
# html_theme = "sphinx_rtd_theme"
165
162
166
163
# Custom sidebar templates, maps document names to template names.
167
- html_sidebars = {
168
- "**" : ["search-field.html" , "sidebar-nav-bs.html" ]
169
- }
164
+ html_sidebars = {"**" : ["search-field.html" , "sidebar-nav-bs.html" ]}
170
165
171
166
# The name of an image file (within the static path) to use as favicon of the
172
167
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
173
168
# pixels large.
174
- html_favicon = str (docs_root / ' _static' / ' m104.ico' )
169
+ html_favicon = str (docs_root / " _static" / " m104.ico" )
175
170
176
171
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
177
172
# using the given strftime format.
178
- #html_last_updated_fmt = ''
173
+ # html_last_updated_fmt = ''
179
174
180
175
# The name for this set of Sphinx documents. If None, it defaults to
181
176
# "<project> v<release> documentation".
182
- html_title = ' {0} v{1}' .format (project , release )
177
+ html_title = " {0} v{1}" .format (project , release )
183
178
184
179
# Output file base name for HTML help builder.
185
- htmlhelp_basename = project + ' doc'
180
+ htmlhelp_basename = project + " doc"
186
181
187
182
# Static files to copy after template files
188
- html_static_path = ['_static' ]
189
- html_css_files = [
190
- "gala.css"
191
- ]
183
+ html_static_path = ["_static" ]
184
+ html_css_files = ["gala.css" ]
192
185
193
186
194
187
# -- Options for LaTeX output --------------------------------------------------
195
188
196
189
# Grouping the document tree into LaTeX files. List of tuples
197
190
# (source start file, target name, title, author, documentclass [howto/manual]).
198
- latex_documents = [('index' , project + '.tex' , project + u' Documentation' ,
199
- author , 'manual' )]
191
+ latex_documents = [
192
+ ("index" , project + ".tex" , project + " Documentation" , author , "manual" )
193
+ ]
200
194
201
195
# show inherited members for classes
202
196
automodsumm_inherited_members = True
203
197
204
198
# Add nbsphinx
205
199
extensions += [
206
- ' nbsphinx' ,
207
- ' IPython.sphinxext.ipython_console_highlighting' ,
208
- ' sphinxcontrib.bibtex' ,
209
- ' rtds_action'
200
+ " nbsphinx" ,
201
+ " IPython.sphinxext.ipython_console_highlighting" ,
202
+ " sphinxcontrib.bibtex" ,
203
+ " rtds_action" ,
210
204
]
211
205
212
206
# Bibliography:
213
- bibtex_bibfiles = [' refs.bib' ]
214
- bibtex_reference_style = ' author_year'
207
+ bibtex_bibfiles = [" refs.bib" ]
208
+ bibtex_reference_style = " author_year"
215
209
216
210
# Custom setting for nbsphinx - timeout for executing one cell
217
211
nbsphinx_timeout = 300
218
- nbsphinx_kernel_name = os .environ .get (' NBSPHINX_KERNEL_NAME' , ' python3' )
212
+ nbsphinx_kernel_name = os .environ .get (" NBSPHINX_KERNEL_NAME" , " python3" )
219
213
220
214
# nbsphinx hacks (thanks exoplanet)
221
215
import nbsphinx
225
219
"{%- if width %}" , "{%- if 0 %}"
226
220
).replace ("{%- if height %}" , "{%- if 0 %}" )
227
221
222
+
228
223
def subber (m ):
229
224
return m .group (0 ).replace ("``" , "`" )
230
225
226
+
231
227
prog = re .compile (r":(.+):``(.+)``" )
232
228
229
+
233
230
def markdown2rst (text ):
234
231
return prog .sub (subber , original_markdown2rst (text ))
235
232
233
+
236
234
nbsphinx .markdown2rst = markdown2rst
237
235
238
236
# rtds-action
239
237
if "GITHUB_TOKEN" in os .environ :
240
238
print ("GitHub Token found: retrieving artifact" )
241
239
242
240
# The name of your GitHub repository
243
- rtds_action_github_repo = setup_cfg [ 'github_project' ]
241
+ rtds_action_github_repo = "adrn/gala"
244
242
245
243
# The path where the artifact should be extracted
246
244
# Note: this is relative to the conf.py file!
@@ -257,28 +255,33 @@ def markdown2rst(text):
257
255
rtds_action_error_if_missing = True
258
256
259
257
else :
260
- rtds_action_github_repo = ''
261
- rtds_action_github_token = ''
262
- rtds_action_path = ''
258
+ rtds_action_github_repo = ""
259
+ rtds_action_github_token = ""
260
+ rtds_action_path = ""
263
261
264
262
## -- Retrieve Zenodo record for most recent version of Gala:
265
- zenodo_path = docs_root / ' ZENODO.rst'
263
+ zenodo_path = docs_root / " ZENODO.rst"
266
264
if not zenodo_path .exists ():
267
265
import textwrap
266
+
268
267
try :
269
268
import requests
270
- headers = {'accept' : 'application/x-bibtex' }
271
- response = requests .get ('https://zenodo.org/api/records/4159870' ,
272
- headers = headers )
273
- response .encoding = 'utf-8'
274
- zenodo_record = (".. code-block:: bibtex\n \n " +
275
- textwrap .indent (response .text , " " * 4 ))
269
+
270
+ headers = {"accept" : "application/x-bibtex" }
271
+ response = requests .get (
272
+ "https://zenodo.org/api/records/4159870" , headers = headers
273
+ )
274
+ response .encoding = "utf-8"
275
+ zenodo_record = ".. code-block:: bibtex\n \n " + textwrap .indent (
276
+ response .text , " " * 4
277
+ )
276
278
except Exception as e :
277
279
warnings .warn (f"Failed to retrieve Zenodo record for Gala: { str (e )} " )
278
- zenodo_record = ("`Retrieve the Zenodo record here "
279
- "<https://zenodo.org/record/4159870>`_" )
280
+ zenodo_record = (
281
+ "`Retrieve the Zenodo record here " "<https://zenodo.org/record/4159870>`_"
282
+ )
280
283
281
- with open (zenodo_path , 'w' ) as f :
284
+ with open (zenodo_path , "w" ) as f :
282
285
f .write (zenodo_record )
283
286
284
287
## -- Check for executed tutorials and only add to toctree if they exist:
@@ -291,7 +294,7 @@ def markdown2rst(text):
291
294
"tutorials/mock-stream-heliocentric.rst" ,
292
295
"tutorials/circ-restricted-3body.rst" ,
293
296
"tutorials/define-milky-way-model.ipynb" ,
294
- "tutorials/Arbitrary-density-SCF.ipynb"
297
+ "tutorials/Arbitrary-density-SCF.ipynb" ,
295
298
]
296
299
297
300
_not_executed = []
@@ -303,7 +306,7 @@ def markdown2rst(text):
303
306
_tutorial_toctree_items .append (fn )
304
307
305
308
if _tutorial_toctree_items :
306
- _tutorial_toctree_items = ' \n ' .join (_tutorial_toctree_items )
309
+ _tutorial_toctree_items = " \n " .join (_tutorial_toctree_items )
307
310
_tutorial_toctree = f"""
308
311
.. toctree::
309
312
:maxdepth: 1
@@ -313,16 +316,17 @@ def markdown2rst(text):
313
316
"""
314
317
315
318
else :
316
- _tutorial_toctree_items = ' No tutorials found!'
319
+ _tutorial_toctree_items = " No tutorials found!"
317
320
318
321
if _not_executed :
319
322
print (
320
323
"\n -------- Gala warning --------\n "
321
324
"Some tutorial notebooks could not be found! This is likely because "
322
325
"the tutorial notebooks have not been executed. If you are building "
323
326
"the documentation locally, you may want to run 'make exectutorials' "
324
- "before running the sphinx build." )
327
+ "before running the sphinx build."
328
+ )
325
329
print (f"Missing tutorials: { ', ' .join (_not_executed )} \n " )
326
330
327
- with open (' _tutorials.rst' , 'w' ) as f :
331
+ with open (" _tutorials.rst" , "w" ) as f :
328
332
f .write (_tutorial_toctree )
0 commit comments