Skip to content

Commit ac0f03b

Browse files
Merge pull request #138 from marcobarilari/marco_sphinx-docs
set up sphinx doc
2 parents 0b51544 + 19fd82f commit ac0f03b

File tree

11 files changed

+604
-1
lines changed

11 files changed

+604
-1
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@
66
# exclude content of logfiles folders
77
*.tsv
88
*.mat
9-
check_my_code_report.txt
9+
check_my_code_report.txt
10+
11+
# exclude content of files for virtual env (mostly for the doc)
12+
cpp_ptb
13+
14+
# ignore file created by sphynx
15+
/docs/build

.readthedocs.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Build documentation in the docs/ directory with Sphinx
9+
sphinx:
10+
configuration: docs/source/conf.py
11+
builder: html
12+
fail_on_warning: true
13+
14+
# Build documentation with MkDocs
15+
#mkdocs:
16+
# configuration: mkdocs.yml
17+
18+
# Optionally build your docs in additional formats such as PDF
19+
formats:
20+
- pdf
21+
22+
# Optionally set the version of Python and requirements required to build your docs
23+
python:
24+
version: 3.7
25+
install:
26+
- requirements: docs/requirements.txt

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Setting up sphinx to create a matlab doc
2+
3+
## Set up virtual environment
4+
5+
```bash
6+
virtualenv -p python3 cpp_ptb
7+
source cpp_ptb/bin/activate
8+
9+
pip install -r requirements.txt
10+
```
11+
12+
## Quick start on the doc
13+
14+
See the [sphinx doc](https://www.sphinx-doc.org/en/master/usage/quickstart.html)
15+
for more.
16+
17+
This
18+
[blog post](https://medium.com/@richdayandnight/a-simple-tutorial-on-how-to-document-your-python-project-using-sphinx-and-rinohtype-177c22a15b5b)
19+
is also useful.
20+
21+
```bash
22+
cd docs
23+
sphinx-quickstart # launch a basic interactive set up of sphinx
24+
```
25+
26+
Answer the questions on prompt.
27+
28+
## Setting up conf.py for matlab doc
29+
30+
Following the documentation from
31+
[matlabdomain for sphinx](https://github.com/sphinx-contrib/matlabdomain).
32+
33+
Specify the extensions you are using:
34+
35+
```python
36+
extensions = [
37+
'sphinxcontrib.matlab',
38+
'sphinx.ext.autodoc']
39+
```
40+
41+
`matlab_src_dir` in `docs/source/conf.py` should have the path (relative to `conf.py`)
42+
to the folder containing your matlab code:
43+
44+
```python
45+
matlab_src_dir = os.path.dirname(os.path.abspath('../../src'))
46+
```
47+
48+
## reStructured text markup
49+
50+
reStructured text mark up
51+
[primer](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html).
52+
53+
## "Templates"
54+
55+
There are different ways you can document the help section of your matlab
56+
functions so it can be documented automatically by sphinx.
57+
58+
```matlab
59+
function y = my_function(arg1, arg2)
60+
%
61+
% Describe what the function does here.
62+
%
63+
% y = my_function_napoleon(arg1, arg2)
64+
%
65+
% :param arg1: The first input value
66+
% :param arg2: The second input value
67+
% :returns: The input value multiplied by two
68+
69+
y = arg1 + arg2
70+
```
71+
72+
"Napoleon" way more similar to Numpy:
73+
74+
```matlab
75+
function y = my_function_napoleon(arg1, arg2)
76+
%
77+
% Describe what the function does here.
78+
%
79+
% y = my_function_napoleon(arg1, arg2)
80+
%
81+
% Parameters:
82+
% x: The first input value
83+
%
84+
% y: The second input value
85+
%
86+
% Returns:
87+
% The input value multiplied by two
88+
89+
y = x * 2;
90+
```
91+
92+
You then just need to insert this in your `.rst` file for the documentation to
93+
be done automatically.
94+
95+
```rst
96+
97+
.. automodule:: src .. <-- This is necessary for autodocumenting the rest
98+
99+
.. autofunction:: my_function
100+
101+
.. autofunction:: my_function_napoleon
102+
```
103+
104+
## Build the documentation locally
105+
106+
From the `docs` directory:
107+
108+
```bash
109+
sphinx-build -b html source build
110+
```
111+
112+
This will build an html version of the doc in the `build` folder.
113+
114+
## Buid the documentation with Read the Docs
115+
116+
Add a [`.readthedocs.yml`](../.readthedocs.yml) file in the root of your repo.
117+
118+
See [HERE](https://docs.readthedocs.io/en/stable/config-file/v2.html) for
119+
details.
120+
121+
You can then trigger the build of the doc by going to the [read the docs](https://readthedocs.org)
122+
website.
123+
124+
You might need to be added as a maintainer of the doc.
125+
126+
The doc can be built from any branch of a repo.
127+
128+
<!-- TODO -->
129+
130+
## Other matlab projects that use
131+
132+
### Sphinx
133+
134+
Some are listed
135+
[sphinx-contrib/matlabdomain#users](https://github.com/sphinx-contrib/matlabdomain#users)
136+
137+
### Read the docs
138+
139+
- [qMRLab](https://github.com/qMRLab/qMRLab/wiki/Guideline:-Generating-Documentation)

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=.
11+
set BUILDDIR=_build
12+
13+
if "%1" == "" goto help
14+
15+
%SPHINXBUILD% >NUL 2>NUL
16+
if errorlevel 9009 (
17+
echo.
18+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19+
echo.installed, then set the SPHINXBUILD environment variable to point
20+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
21+
echo.may add the Sphinx directory to PATH.
22+
echo.
23+
echo.If you don't have Sphinx installed, grab it from
24+
echo.http://sphinx-doc.org/
25+
exit /b 1
26+
)
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sphinx
2+
sphinxcontrib-matlabdomain
3+
sphinxcontrib-napoleon
4+
sphinx_rtd_theme
14.2 KB
Loading

docs/source/conf.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.abspath('../..'))
16+
17+
# -- Project information -----------------------------------------------------
18+
19+
project = 'CPP_PTB'
20+
copyright = '2020, CPP_PTB developers'
21+
author = 'CPP_PTB developers'
22+
23+
# The full version, including alpha/beta/rc tags
24+
release = 'v1.0.0'
25+
26+
27+
# -- General configuration ---------------------------------------------------
28+
29+
# Add any Sphinx extension module names here, as strings. They can be
30+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
31+
# ones.
32+
extensions = [
33+
'sphinxcontrib.matlab',
34+
'sphinx.ext.autodoc']
35+
matlab_src_dir = os.path.dirname(os.path.abspath('../../src'))
36+
primary_domain = 'mat'
37+
38+
# Add any paths that contain templates here, relative to this directory.
39+
templates_path = ['_templates']
40+
41+
# List of patterns, relative to source directory, that match files and
42+
# directories to ignore when looking for source files.
43+
# This pattern also affects html_static_path and html_extra_path.
44+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
45+
46+
# -- Options for HTML output -------------------------------------------------
47+
48+
# The theme to use for HTML and HTML Help pages. See the documentation for
49+
# a list of builtin themes.
50+
#
51+
html_theme = 'sphinx_rtd_theme'
52+
53+
# Add any paths that contain custom static files (such as style sheets) here,
54+
# relative to this directory. They are copied after the builtin static files,
55+
# so a file named "default.css" will overwrite the builtin "default.css".
56+
html_static_path = ['_static']
57+
58+
html_logo = '_static/cpp_lab_logo.png'
59+
60+
# html_theme_options = {
61+
# 'github_user': 'cpp-lln-lab',
62+
# 'github_repo': 'CPP_BIDS_SPM_pipeline',
63+
# 'github_button': True,
64+
# 'github_banner': True
65+
# }
66+
# html_theme_options = {
67+
# 'collapse_navigation': False,
68+
# 'display_version': False,
69+
# 'navigation_depth': 4,
70+
# }
71+
72+
html_sidebars = {
73+
'**': [
74+
'about.html',
75+
'navigation.html',
76+
'relations.html', # needs 'show_related': True theme option to display
77+
'searchbox.html',
78+
'donate.html',
79+
]
80+
}

0 commit comments

Comments
 (0)