Skip to content

Commit 6a884ef

Browse files
authored
Merge pull request #120 from Remi-Gau/remi-doc
[DOC] implement sphinx doc and read the docs
2 parents b6de523 + 132647e commit 6a884ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1186
-3758
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ check_my_code_report.txt
3030
node_modules/*
3131
package-lock.json
3232

33+
# visual studio code stuff
34+
.vscode
3335

36+
# virtual env
37+
cpp_bids/*
38+
39+
# documentation
40+
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

.travis.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33
# have set it up to run continuous integration on this this repo
44

55
# Linux distribution (bionic beaver)
6-
dist: bionic
6+
dist: focal
77

88
# Language and version
99
language: node_js
1010
node_js:
11-
- "10"
12-
13-
cache:
14-
apt: true # only works with Pro version
15-
directories:
16-
- node_modules # NPM packages for the remark markdown linter
11+
- "11"
1712

1813
branches:
1914
only: # only run the CI for those branches
@@ -33,7 +28,7 @@ before_install:
3328
- travis_retry sudo apt-get -y install nodejs
3429
- travis_retry sudo apt-get -y install npm
3530
# Install BIDS-Validator
36-
- sudo npm install -g [email protected].6
31+
- sudo npm install -g [email protected].7
3732

3833
install:
3934
# make octave file the JSONio submodule

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 = source
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: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Setting up sphinx to create a matlab doc
2+
3+
## Set up virtual environment
4+
5+
```bash
6+
virtualenv -p python3 cpp_bids
7+
source cpp_spm/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
42+
`conf.py`) 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 primers:
51+
52+
- on the [sphinx site](https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html)
53+
54+
- more
55+
[python oriented](https://pythonhosted.org/an_example_pypi_project/sphinx.html)
56+
57+
- typical doc strings templates
58+
- [google way](https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html)
59+
- [numpy](https://www.sphinx-doc.org/en/master/usage/extensions/example_numpy.html#example-numpy)
60+
61+
## "Templates"
62+
63+
The templates to use for the doc are in the `src/templates` folder.
64+
65+
You then just need to insert this in your `.rst` file for the documentation to
66+
be done automatically.
67+
68+
```rst
69+
70+
.. automodule:: src.folder_name .. <-- This is necessary for auto-documenting the rest
71+
72+
.. autofunction:: function to document
73+
74+
```
75+
76+
To get the filenames of all the functions in a folder:
77+
78+
``` bash
79+
ls -l src/*.m | cut -c42- | rev | cut -c 3- | rev
80+
```
81+
82+
Increase the `42` to crop more characters at the beginning.
83+
84+
Change the `3` to crop more characters at the end.
85+
86+
## Build the documentation locally
87+
88+
From the `docs` directory:
89+
90+
```bash
91+
sphinx-build -b html source build
92+
```
93+
94+
This will build an html version of the doc in the `build` folder.
95+
96+
## Build the documentation with Read the Docs
97+
98+
Add a [`.readthedocs.yml`](../.readthedocs.yml) file in the root of your repo.
99+
100+
See [HERE](https://docs.readthedocs.io/en/stable/config-file/v2.html) for
101+
details.
102+
103+
You can then trigger the build of the doc by going to the
104+
[read the docs website](https://readthedocs.org).
105+
106+
You might need to be added as a maintainer of the doc.
107+
108+
The doc can be built from any branch of a repo.

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=source
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Sphinx
2+
sphinxcontrib-matlabdomain
3+
sphinxcontrib-napoleon
4+
sphinx_rtd_theme
5+
miss_hit
14.2 KB
Loading

docs/source/conf.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
18+
# -- Project information -----------------------------------------------------
19+
20+
project = 'CPP BIDS'
21+
copyright = '2020, the CPP BIDS dev team'
22+
author = 'the CPP BIDS dev team'
23+
24+
# The full version, including alpha/beta/rc tags
25+
release = 'v1.0.0'
26+
27+
28+
# -- General configuration ---------------------------------------------------
29+
30+
# Add any Sphinx extension module names here, as strings. They can be
31+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32+
# ones.
33+
extensions = [
34+
'sphinxcontrib.matlab',
35+
'sphinx.ext.autodoc']
36+
matlab_src_dir = os.path.dirname(os.path.abspath('../../src'))
37+
primary_domain = 'mat'
38+
39+
# Add any paths that contain templates here, relative to this directory.
40+
templates_path = ['_templates']
41+
42+
# List of patterns, relative to source directory, that match files and
43+
# directories to ignore when looking for source files.
44+
# This pattern also affects html_static_path and html_extra_path.
45+
exclude_patterns = []
46+
47+
# The name of the Pygments (syntax highlighting) style to use.
48+
pygments_style = 'sphinx'
49+
50+
# The master toctree document.
51+
master_doc = 'index'
52+
53+
# source_suffix = ['.rst', '.md']
54+
source_suffix = '.rst'
55+
56+
57+
# -- Options for HTML output -------------------------------------------------
58+
59+
# The theme to use for HTML and HTML Help pages. See the documentation for
60+
# a list of builtin themes.
61+
#
62+
html_theme = 'sphinx_rtd_theme'
63+
64+
# Add any paths that contain custom static files (such as style sheets) here,
65+
# relative to this directory. They are copied after the builtin static files,
66+
# so a file named "default.css" will overwrite the builtin "default.css".
67+
html_static_path = ['_static']
68+
69+
html_logo = '_static/cpp_lab_logo.png'
70+
71+
# html_theme_options = {
72+
# 'github_user': 'cpp-lln-lab',
73+
# 'github_repo': 'CPP_BIDS_SPM_pipeline',
74+
# 'github_button': True,
75+
# 'github_banner': True
76+
# }
77+
# html_theme_options = {
78+
# 'collapse_navigation': False,
79+
# 'display_version': False,
80+
# 'navigation_depth': 4,
81+
# }
82+
83+
html_sidebars = {
84+
'**': [
85+
'about.html',
86+
'navigation.html',
87+
'relations.html', # needs 'show_related': True theme option to display
88+
'searchbox.html',
89+
'donate.html',
90+
]
91+
}

0 commit comments

Comments
 (0)