|
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 |
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 |
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 |
122 | | -[read the docs](https://readthedocs.org) 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) |
| 1 | +Information on how to write and build the documentation can be found in our |
| 2 | +[CONTRIBUTING guidelines](https://github.com/cpp-lln-lab/.github/blob/main/CONTRIBUTING.md). |
0 commit comments