Skip to content

Commit 6b9a2ed

Browse files
committed
update sphinx conf to not require setup.cfg
1 parent 9afae7e commit 6b9a2ed

File tree

1 file changed

+93
-89
lines changed

1 file changed

+93
-89
lines changed

docs/conf.py

+93-89
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,35 @@
1212
try:
1313
from sphinx_astropy.conf.v1 import * # noqa
1414
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+
)
1719
sys.exit(1)
1820

1921
# Get configuration information from setup.cfg
2022
from configparser import ConfigParser
23+
2124
conf = ConfigParser()
2225

2326
docs_root = pathlib.Path(__file__).parent.resolve()
24-
conf.read([str(docs_root / '..' / 'setup.cfg')])
25-
setup_cfg = dict(conf.items('metadata'))
2627

2728
# -- General configuration ----------------------------------------------------
2829

2930
# By default, highlight as Python 3.
30-
highlight_language = 'python3'
31+
highlight_language = "python3"
3132

3233
# List of patterns, relative to source directory, that match files and
3334
# directories to ignore when looking for source files.
34-
exclude_patterns = ['_build', '**.ipynb_checkpoints']
35+
exclude_patterns = ["_build", "**.ipynb_checkpoints"]
3536

3637
# Add any paths that contain templates here, relative to this directory.
37-
templates_path = ['_templates']
38+
templates_path = ["_templates"]
3839

3940
# The suffix(es) of source filenames.
4041
# You can specify multiple suffix as a list of string:
4142
# source_suffix = ['.rst', '.md']
42-
source_suffix = '.rst'
43+
source_suffix = ".rst"
4344

4445
# Don't show summaries of the members in each class along with the
4546
# class' docstring
@@ -51,11 +52,11 @@
5152

5253
autosummary_generate = True
5354

54-
automodapi_toctreedirnm = 'api'
55+
automodapi_toctreedirnm = "api"
5556

5657
# The reST default role (used for this markup: `text`) to use for all
5758
# documents. Set to the "smart" one.
58-
default_role = 'obj'
59+
default_role = "obj"
5960

6061
# Class documentation should contain *both* the class docstring and
6162
# the __init__ docstring
@@ -68,13 +69,13 @@
6869

6970
# intersphinx
7071
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),
7879
}
7980

8081
# Show / hide TODO blocks
@@ -83,63 +84,59 @@
8384
# -- Project information ------------------------------------------------------
8485

8586
# 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)
9090

91-
package_name = 'gala'
91+
package_name = "gala"
9292
import_module(package_name)
9393
package = sys.modules[package_name]
9494

9595
from cmastro import cmaps
96-
plot_formats = [('png', 200), ('pdf', 200)]
96+
97+
plot_formats = [("png", 200), ("pdf", 200)]
9798
plot_apply_rcparams = True
9899
# NOTE: if you update these, also update docs/tutorials/nb_setup
99100
plot_rcparams = {
100-
'image.cmap': 'cma:hesperia',
101-
101+
"image.cmap": "cma:hesperia",
102102
# 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",
110109
# Axes:
111-
'axes.labelcolor': 'k',
112-
'axes.axisbelow': True,
113-
110+
"axes.labelcolor": "k",
111+
"axes.axisbelow": True,
114112
# 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,
124121
}
125122
plot_include_source = False
126123

127124
# The short X.Y version.
128-
version = package.__version__.split('-', 1)[0]
125+
version = package.__version__.split("-", 1)[0]
129126
# The full version, including alpha/beta/rc tags.
130127
release = package.__version__
131128

132129

133130
# -- Options for HTML output ---------------------------------------------------
134131

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"
137134

138135
html_theme_options = {
139136
"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+
},
143140
"icon_links": [
144141
{
145142
"name": "GitHub",
@@ -164,58 +161,55 @@
164161
# html_theme = "sphinx_rtd_theme"
165162

166163
# 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"]}
170165

171166
# The name of an image file (within the static path) to use as favicon of the
172167
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
173168
# pixels large.
174-
html_favicon = str(docs_root / '_static' / 'm104.ico')
169+
html_favicon = str(docs_root / "_static" / "m104.ico")
175170

176171
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
177172
# using the given strftime format.
178-
#html_last_updated_fmt = ''
173+
# html_last_updated_fmt = ''
179174

180175
# The name for this set of Sphinx documents. If None, it defaults to
181176
# "<project> v<release> documentation".
182-
html_title = '{0} v{1}'.format(project, release)
177+
html_title = "{0} v{1}".format(project, release)
183178

184179
# Output file base name for HTML help builder.
185-
htmlhelp_basename = project + 'doc'
180+
htmlhelp_basename = project + "doc"
186181

187182
# 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"]
192185

193186

194187
# -- Options for LaTeX output --------------------------------------------------
195188

196189
# Grouping the document tree into LaTeX files. List of tuples
197190
# (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+
]
200194

201195
# show inherited members for classes
202196
automodsumm_inherited_members = True
203197

204198
# Add nbsphinx
205199
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",
210204
]
211205

212206
# Bibliography:
213-
bibtex_bibfiles = ['refs.bib']
214-
bibtex_reference_style = 'author_year'
207+
bibtex_bibfiles = ["refs.bib"]
208+
bibtex_reference_style = "author_year"
215209

216210
# Custom setting for nbsphinx - timeout for executing one cell
217211
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")
219213

220214
# nbsphinx hacks (thanks exoplanet)
221215
import nbsphinx
@@ -225,22 +219,26 @@
225219
"{%- if width %}", "{%- if 0 %}"
226220
).replace("{%- if height %}", "{%- if 0 %}")
227221

222+
228223
def subber(m):
229224
return m.group(0).replace("``", "`")
230225

226+
231227
prog = re.compile(r":(.+):``(.+)``")
232228

229+
233230
def markdown2rst(text):
234231
return prog.sub(subber, original_markdown2rst(text))
235232

233+
236234
nbsphinx.markdown2rst = markdown2rst
237235

238236
# rtds-action
239237
if "GITHUB_TOKEN" in os.environ:
240238
print("GitHub Token found: retrieving artifact")
241239

242240
# The name of your GitHub repository
243-
rtds_action_github_repo = setup_cfg['github_project']
241+
rtds_action_github_repo = "adrn/gala"
244242

245243
# The path where the artifact should be extracted
246244
# Note: this is relative to the conf.py file!
@@ -257,28 +255,33 @@ def markdown2rst(text):
257255
rtds_action_error_if_missing = True
258256

259257
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 = ""
263261

264262
## -- Retrieve Zenodo record for most recent version of Gala:
265-
zenodo_path = docs_root / 'ZENODO.rst'
263+
zenodo_path = docs_root / "ZENODO.rst"
266264
if not zenodo_path.exists():
267265
import textwrap
266+
268267
try:
269268
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+
)
276278
except Exception as e:
277279
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+
)
280283

281-
with open(zenodo_path, 'w') as f:
284+
with open(zenodo_path, "w") as f:
282285
f.write(zenodo_record)
283286

284287
## -- Check for executed tutorials and only add to toctree if they exist:
@@ -291,7 +294,7 @@ def markdown2rst(text):
291294
"tutorials/mock-stream-heliocentric.rst",
292295
"tutorials/circ-restricted-3body.rst",
293296
"tutorials/define-milky-way-model.ipynb",
294-
"tutorials/Arbitrary-density-SCF.ipynb"
297+
"tutorials/Arbitrary-density-SCF.ipynb",
295298
]
296299

297300
_not_executed = []
@@ -303,7 +306,7 @@ def markdown2rst(text):
303306
_tutorial_toctree_items.append(fn)
304307

305308
if _tutorial_toctree_items:
306-
_tutorial_toctree_items = '\n '.join(_tutorial_toctree_items)
309+
_tutorial_toctree_items = "\n ".join(_tutorial_toctree_items)
307310
_tutorial_toctree = f"""
308311
.. toctree::
309312
:maxdepth: 1
@@ -313,16 +316,17 @@ def markdown2rst(text):
313316
"""
314317

315318
else:
316-
_tutorial_toctree_items = 'No tutorials found!'
319+
_tutorial_toctree_items = "No tutorials found!"
317320

318321
if _not_executed:
319322
print(
320323
"\n-------- Gala warning --------\n"
321324
"Some tutorial notebooks could not be found! This is likely because "
322325
"the tutorial notebooks have not been executed. If you are building "
323326
"the documentation locally, you may want to run 'make exectutorials' "
324-
"before running the sphinx build.")
327+
"before running the sphinx build."
328+
)
325329
print(f"Missing tutorials: {', '.join(_not_executed)}\n")
326330

327-
with open('_tutorials.rst', 'w') as f:
331+
with open("_tutorials.rst", "w") as f:
328332
f.write(_tutorial_toctree)

0 commit comments

Comments
 (0)