-
Notifications
You must be signed in to change notification settings - Fork 20
/
conf.py
229 lines (187 loc) · 6.22 KB
/
conf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# CLMM documentation build configuration file, created by
import os
import subprocess
import sys
sys.path.insert(0, os.path.abspath("../clmm"))
sys.path.insert(0, os.path.abspath(".."))
from unittest.mock import MagicMock
MOCK_MODULES = [
"gi",
"gi.repository",
"gi.repository.NumCosmoMath",
"gi.repository.NumCosmo",
"pyccl",
]
for mod_name in MOCK_MODULES:
sys.modules[mod_name] = MagicMock()
# Fix for ccl
sys.modules["pyccl"].Cosmology = MagicMock
sys.modules["pyccl"].__version__ = "3"
# Fix for numcosmo
sys.modules["gi.repository"].NumCosmo.Distance = MagicMock
sys.modules["gi.repository"].NumCosmo.Distance.new = MagicMock
sys.modules["gi.repository"].NumCosmo.Distance.new.prepare_if_needed = MagicMock
import clmm
# -- RTD Fix for cluster_toolkit -----------------------------------------
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
# This code will execute only on readthedocs
if on_rtd:
try:
from unittest.mock import MagicMock
except ImportError:
from mock import Mock as MagicMock
class Mock(MagicMock):
@classmethod
def __getattr__(cls, name):
return MagicMock()
# For these modules, do a mock import
MOCK_MODULES = ["cluster_toolkit"]
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
# -- Load the version number ----------------------------------------------
version = clmm.__version__
release = version
# -- General configuration ------------------------------------------------
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.viewcode",
"sphinx.ext.napoleon",
"sphinx.ext.githubpages",
"IPython.sphinxext.ipython_console_highlighting",
]
apidoc_module_dir = "../clmm"
# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
source_suffix = [".rst", ".md"]
# The master toctree document.
master_doc = "index"
# General information about the project.
project = "CLMM"
copyright = "2018-2021, LSST DESC CLMM Contributors"
author = "LSST DESC CLMM Contributors"
language = "en"
# Files to ignore when looking for source files
exclude_patterns = [
"_build",
"Thumbs.db",
".DS_Store",
"api/clmm.rst",
"source/index_body.rst",
"api/clmm.cluster_toolkit_patches.rst",
"api/clmm.modbackend.*",
".precompiled-fixed-examples/*",
]
# Some style options
highlight_language = "python3"
pygments_style = "sphinx"
todo_include_todos = True
add_function_parentheses = True
add_module_names = True
smartquotes = False
# -- Options for HTML output ----------------------------------------------
# HTML Theme
html_theme = "sphinx_rtd_theme"
html_theme_options = {
"prev_next_buttons_location": None,
"collapse_navigation": False,
"titles_only": True,
}
html_static_path = []
# -- Options for Napoleon-------------------------------------------------
# Napoleon compiles the docstrings into .rst
# If True, include class __init__ docstrings separately from class
napoleon_include_init_with_doc = False
# If True, include docstrings of private functions
napoleon_include_private_with_doc = False
# Detail for converting docstrings to rst
napoleon_use_ivar = True
# -- Options for Autodoc--------------------------------------------------
# Autodoc collects docstrings and builds API pages
# def run_apidoc(_):
# from sphinxcontrib.apidoc import main as apidoc_main
# cur_dir = os.path.normpath(os.path.dirname(__file__))
# output_path = os.path.join(cur_dir, 'api')
# modules = os.path.normpath(os.path.join(cur_dir, "../clmm"))
# paramlist = ['--separate', '--no-toc', '-f', '-M', '-o', output_path, modules]
# apidoc_main(paramlist)
# def setup(app):
# app.connect('builder-inited', run_apidoc)
# -- Load from the config file -------------------------------------------
config = open("doc-config.ini").read().strip().split("\n")
doc_files = {
"APIDOC": [],
"DEMO": [],
"EXAMPLE": [],
"OTHER": [],
}
key = None
for entry in config:
if not entry or entry[0] == "#":
continue
elif entry in doc_files:
key = entry
else:
doc_files[key].append(entry)
# -- Compile the examples into rst----------------------------------------
run_nb = False
outdir = "compiled-examples/"
nbconvert_opts = [
"--to rst",
"--ExecutePreprocessor.kernel_name=python3",
"--execute",
f"--output-dir {outdir}",
]
nb_skip_run = [
# '../examples/DC2/data_and_model_demo_DC2.ipynb',
# '../examples/mass_fitting/Example4_Fit_Halo_mass_to_HSC_data.ipynb',
# '../examples/mass_fitting/Example5_Fit_Halo_mass_to_DES_data.ipynb',
]
for lists in [v for k, v in doc_files.items() if k != "APIDOC"]:
for demo in lists:
com = " ".join(["jupyter nbconvert"] + nbconvert_opts + [demo])
if demo in nb_skip_run or not run_nb:
com = com.replace(" --execute ", " ")
subprocess.run(com, shell=True)
for nb in nb_skip_run:
pref = nb.split("/")[-1].replace(".ipynb", "")
com = f"cp -rf .precompiled-fixed-examples/{pref}* compiled-examples/"
print(f"* Fix for publication (use precompiled version of {pref} from older version)")
subprocess.run(com, shell=True)
# -- Build index.html ----------------------------------------------------
doc_captions = {
"DEMO": "Usage Demos",
"EXAMPLE": "Mass Fitting Examples",
"OTHER": "Other",
}
index_toc = ""
for CASE in ("DEMO", "EXAMPLE", "OTHER"):
index_toc += f"""
.. toctree::
:maxdepth: 1
:caption: {doc_captions[CASE]}
"""
for example in doc_files[CASE]:
fname = "".join(example.split(".")[:-1]).split("/")[-1] + ".rst"
index_toc += f" {outdir}{fname}\n"
subprocess.run("cp source/index_body.rst index.rst", shell=True)
with open("index.rst", "a") as indexfile:
indexfile.write(index_toc)
indexfile.write(
"""
.. toctree::
:maxdepth: 1
:caption: Reference
api
"""
)
# -- Set up the API table of contents ------------------------------------
apitoc = """API Documentation
-----------------
Information on specific functions, classes, and methods.
.. toctree::
:glob:
"""
for onemodule in doc_files["APIDOC"]:
apitoc += f" api/clmm.{onemodule}.rst\n"
with open("api.rst", "w") as apitocfile:
apitocfile.write(apitoc)