Skip to content

Commit 4894385

Browse files
Implement QuaLiKiz style Sphinx docs
1 parent 326a362 commit 4894385

File tree

4 files changed

+49
-32
lines changed

4 files changed

+49
-32
lines changed

docs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ help:
2020
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
2121
%: Makefile
2222
@echo Running '$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)'
23-
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
23+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -Tvv
2424

2525
clean: Makefile
2626
@echo Running '$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)'

docs/source/README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../../README.md

docs/source/conf.py

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,58 +25,54 @@
2525

2626
from pkg_resources import parse_version as V
2727

28-
sys.path.insert(0, "../../install")
28+
import imaspy
29+
2930

3031
print("python exec:", sys.executable)
3132
print("sys.path:", sys.path)
3233

33-
import imaspy
34-
3534
# -- Project information -----------------------------------------------------
3635
# The documented project’s name
3736
project = src_project = PROJECT = "IMASPy"
3837

3938
# PROJECT_ID=10189354
4039
PACKAGE = "imaspy"
4140
PACKAGE_HOST = "gitlab"
42-
src_group = GROUP = "KLIMEX"
41+
src_group = GROUP = "IMAS"
4342

4443
# A copyright statement in the style '2008, Author Name'.
45-
copyright = f"2016-{datetime.datetime.now().year}, Karel van de Plassche (DIFFER)"
44+
copyright = f"2020-{datetime.datetime.now().year}, ITER Organization"
4645
# The author name(s) of the document
47-
author = "Karel van de Plassche (DIFFER)"
48-
src_host = "gitlab.com"
46+
author = "ITER Organization"
47+
src_host = "git.iter.org"
4948

5049
# Parse urls here for convenience, to be re-used
51-
# gitlab imaspy folder
52-
repository_url = f"https://{src_host}/{src_group}/{src_project}/"
53-
blob_url = urljoin(repository_url, "-/blob/master/")
54-
issue_url = urljoin(repository_url, "-/issues/")
55-
mr_url = urljoin(repository_url, "-/merge_requests/")
56-
57-
# JINTRAC docs
58-
jintrac_sphinx = "https://users.euro-fusion.org/pages/data-cmg/wiki/"
5950

6051
# netCDF4 docs
6152
netcdf4_docs = "https://unidata.github.io/netcdf4-python/netCDF4/index.html"
6253

6354
# ITER docs
6455
iter_projects = "https://git.iter.org/projects/"
65-
imas_site = urljoin(iter_projects, "IMAS/")
66-
imex_site = urljoin(iter_projects, "IMEX/")
67-
al_cython_url = urljoin(imas_site, "repos/al-cython/")
68-
al_python_hli_url = urljoin(imas_site, "repos/al-python/")
69-
al_python_lib_url = urljoin(imas_site, "repos/al-python-lib/")
56+
imas_repos = urljoin(iter_projects, "IMAS/")
57+
imex_repos = urljoin(iter_projects, "IMEX/")
58+
al_cython_url = urljoin(imas_repos, "repos/al-cython/")
59+
al_python_hli_url = urljoin(imas_repos, "repos/al-python/")
60+
al_python_lib_url = urljoin(imas_repos, "repos/al-python-lib/")
7061
issue_url = jira_url = "https://jira.iter.org/browse/"
7162

63+
# IMASPy
64+
repository_url = f"{iter_projects}/{src_group}/repos/{src_project}/"
65+
blob_url = urljoin(repository_url, "browse/")
66+
mr_url = urljoin(repository_url, "/pull-requests")
67+
68+
7269
# Configuration of sphinx.ext.extlinks
7370
# See https://www.sphinx-doc.org/en/master/usage/extensions/extlinks.html
7471
# unique name: (base URL, label prefix)
7572
extlinks = {
7673
"src": (blob_url + "%s", f"{src_group}/{src_project}/"),
77-
"issue": (issue_url + "%s", None),
74+
"issue": (issue_url + "%s", "#"),
7875
"merge": (mr_url + "%s", "!"),
79-
"jintrac": (jintrac_sphinx + "%s", "jintrac pages "),
8076
"netcdf4": (netcdf4_docs + "%s", "netcdf4 "),
8177
"al_cython": (al_cython_url + "%s", "al_cython "),
8278
"al_hli": (al_python_hli_url + "%s", "al_hli"),
@@ -115,9 +111,10 @@
115111
# 'matplotlib.sphinxext.plot_directive', # numpy
116112
# 'IPython.sphinxext.ipythoGn_console_highlighting', # numpy
117113
# 'IPython.sphinxext.ipython_directive', # numpy
118-
"sphinx.ext.mathjax", # Render math with mathjax
114+
"sphinx.ext.mathjax", # Render math as images
119115
"sphinx_rtd_theme", # Theme
120116
"recommonmark", # For markdown support, does not support 'full' CommonMark syntax (yet)!
117+
"sphinx_autodoc_typehints", # Auto-parse type hints. Napoleon BEFORE typehints
121118
]
122119

123120
# Add any paths that contain templates here, relative to this directory.
@@ -246,6 +243,11 @@
246243

247244

248245
# -- Extension configuration -------------------------------------------------
246+
# Configuration of sphinx.ext.autodoc
247+
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
248+
autodoc_typehints = "none" # Use sphinx_autodoc_typehints instead
249+
250+
249251
# from recommonmark.transform import AutoStructify
250252

251253
# app setup hook
@@ -265,10 +267,6 @@
265267
# app.add_transform(AutoStructify)
266268

267269

268-
# Configuration of sphinx.ext.autodoc
269-
# https://www.sphinx-doc.org/en/master/usage/quickstart.html#autodoc
270-
# autodoc_typehints = "none" #xarray
271-
272270
# Configuration of sphinx.ext.autosummary
273271
# https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html
274272
autosummary_generate = True
@@ -279,8 +277,8 @@
279277
# Configuration of sphinx.ext.napoleon
280278
# Support for NumPy and Google style docstrings
281279
# See https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html
282-
# napoleon_google_docstring = True
283-
# napoleon_numpy_docstring = True
280+
napoleon_google_docstring = True
281+
napoleon_numpy_docstring = False
284282
napoleon_include_init_with_doc = True
285283
napoleon_include_private_with_doc = True
286284
# napoleon_include_special_with_doc = True
@@ -289,8 +287,9 @@
289287
# napoleon_use_admonition_for_references = False
290288
# napoleon_use_ivar = False
291289
# napoleon_use_param = True
292-
napoleon_use_keyword = True # Use the "Keyword Args" syntax
290+
# napoleon_use_keyword = False
293291
# napoleon_use_rtype = True
292+
napoleon_preprocess_types = True
294293
napoleon_type_aliases = {
295294
# general terms
296295
"sequence": ":term:`sequence`",
@@ -339,7 +338,10 @@
339338
# objects with abbreviated namespace (from pandas)
340339
"pd.Index": "~pandas.Index",
341340
"pd.NaT": "~pandas.NaT",
342-
} # TODO: From xarray, improve!
341+
"pd.DataFrame": "~pandas.NaT",
342+
} # TODO: From xarray, improve! New in 3.2
343+
344+
napoleon_attr_annotations = True # Allow PEP 526 attributes annotations in classes. New in 3.4
343345

344346
# From xarray, huh?
345347
# napoleon_preprocess_types = True #From xarray, not in docs
@@ -369,6 +371,19 @@
369371
# Configuration of sphinx.ext.mathjax
370372
# See https://www.sphinx-doc.org/en/master/usage/extensions/math.html#module-sphinx.ext.mathjax
371373

374+
# Configuration of sphinx_autodoc_typehints
375+
# See https://pypi.org/project/sphinx-autodoc-typehints/
376+
set_type_checking_flag = (
377+
True # Set typing.TYPE_CHECKING to True to enable "expensive" typing imports
378+
)
379+
# typehints_fully_qualified = False # If True, class names are always fully qualified (e.g. module.for.Class). If False, just the class name displays (e.g. Class)
380+
always_document_param_types = (
381+
True # add stub documentation for undocumented parameters to be able to add type info.
382+
)
383+
# typehints_document_rtype = True # If False, never add an :rtype: directive. If True, add the :rtype: directive if no existing :rtype: is found.
384+
# simplify_optional_unions = True # If True, optional parameters of type "Union[...]" are simplified as being of type Union[..., None] in the resulting documention (e.g. Optional[Union[A, B]] -> Union[A, B, None]). # If False, the "Optional"-type is kept. Note: If False, any Union containing None will be displayed as Optional! Note: If an optional parameter has only a single type (e.g Optional[A] or Union[A, None]), it will always be displayed as Optional!
385+
386+
372387
def escape_underscores(string):
373388
return string.replace("_", r"\_")
374389

requirements_docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ sphinx>=3.2.1
22
sphinx_rtd_theme>=0.5
33
recommonmark>=0.6
44
sphinx-autosummary-accessors>=0.1.2
5+
sphinx-autodoc-typehints>=1.1.1

0 commit comments

Comments
 (0)