Skip to content

[DOC] Add sphinx documentation and serve on read the docs#45

Merged
kendrickkay merged 11 commits intocvnlab:mainfrom
Remi-Gau:add_sphinx_doc
Apr 29, 2022
Merged

[DOC] Add sphinx documentation and serve on read the docs#45
kendrickkay merged 11 commits intocvnlab:mainfrom
Remi-Gau:add_sphinx_doc

Conversation

@Remi-Gau
Copy link
Contributor

@Remi-Gau Remi-Gau commented Apr 9, 2022

Small example of a set up to use the Sphinx python package to automatically generate the documentation of the code by reading it from the doc stings (python) or help section (matlab).

This also includes a setup to serve the doc on read the docs.
See the output here: https://glmsingle.readthedocs.io/en/latest/

This example only shows the rendering of the main function but this could be expanded to add more of the utilities function.

Pros: easy to create a website to point users to or even a pdf of the whole documentation (make latexpdf)

Cons: might require to do a light editing of the comments in the code to make them play well with reStructured text (the markup language used by Sphinx) otherwise the rendering is suboptimal.

For a quick intro to all this: https://goodresearch.dev/docs.html#

FYI this is based on the same initial commit as #43 and #44

@Remi-Gau Remi-Gau marked this pull request as ready for review April 9, 2022 10:19
@Remi-Gau Remi-Gau marked this pull request as draft April 9, 2022 10:19
@Remi-Gau
Copy link
Contributor Author

Remi-Gau commented Apr 9, 2022

This is just a suggestion: was also curious to see how to set up the Sphinx for combined Python / Matlab project.
Feel free to reject.

Comment on lines +4 to +10
.. mat:automodule:: matlab

.. mat:autofunction:: GLMestimatesingletrial

.. mat:automodule:: matlab.utilities

.. mat:autofunction:: calccod No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all that is needed to tell Sphinx to read and render the help sections from specific matlab file

Comment on lines +4 to +13
.. module:: glmsingle.glmsingle

.. autoclass:: GLM_single
:members:
:undoc-members:
:show-inheritance:

.. module:: glmsingle.cod.calc_cod

.. autofunction:: calc_cod No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for python but also shows how to deal with classes and their methods

@Remi-Gau Remi-Gau marked this pull request as ready for review April 9, 2022 10:26
@kendrickkay
Copy link
Member

Looks interesting. (But obviously would need clean up.) This is another thing we can earmark for discussion (with Jacob and Ian, too).

Copy link
Contributor Author

@Remi-Gau Remi-Gau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add FAQ as example
  • add template function to show how to format help section in matlab
  • reformat help to render well on read the docs

@Remi-Gau
Copy link
Contributor Author

Wiki has been added: see here https://glmsingle.readthedocs.io/en/latest/wiki.html

Comment on lines -12 to +20
% Note that we ultimately compute single-trial response estimates (one estimate for
% each condition onset), and these will be provided in chronological order. However,
% by specifying that a given condition occurs more than one time over the course
% of the experiment, this information can and will be used for cross-validation purposes.
%
% Note that we ultimately compute single-trial response estimates (one estimate for
% each condition onset), and these will be provided in chronological order. However,
% by specifying that a given condition occurs more than one time over the course
% of the experiment, this information can and will be used for cross-validation purposes.
%
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a "quick fix" of the help section of the main matlab function so that it renders correctly

https://glmsingle.readthedocs.io/en/latest/matlab.html

The only change you would have to do to your usually commenting style so that it plays nice with the restrcutured text markup to sphinx expects would be to use lineskip rather than indents for each of the your parameter definition paragraph.

I will still send some typical template function in case you wanted to adopt something that ressembles some of the other typical commenting styles used in sphinx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case you want to browse the whole function directly: see it on my fork

https://github.com/Remi-Gau/GLMsingle/blob/add_sphinx_doc/matlab/GLMestimatesingletrial.m

Comment on lines +3 to +5
% USAGE::
%
% results = GLMestimatesingletrial(design,data,stimdur,tr,outputdir,opt)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the double :: + lineskip + indent

is what sphinx uses to render code.

The same way that in markdown:

results = GLMestimatesingletrial(design,data,stimdur,tr,outputdir,opt)

is made with this

```matlab
results = GLMestimatesingletrial(design,data,stimdur,tr,outputdir,opt)
```

@kendrickkay
Copy link
Member

I looked over the links and information and stuff. Seems good. If this is ready to go / merge, we could go ahead and pull the trigger and get this squared away (and then I would conform to the new doc philosophy).

@kendrickkay
Copy link
Member

(I presume this merge request is separable from the other ones? If so, we could do this one first, and then proceed to the other ones, next.)

@Remi-Gau
Copy link
Contributor Author

Remi-Gau commented Apr 29, 2022

yes those PR should in principle be merged in any order.

If there is a merge conflict at some point I will fix it when it happens.

After this one is merged there might be some 'configuration' to do:

  • tell read the docs side to build from this repo and not my fork (currently the doc is built from my fork and not from the upstream repo on cvnlab) - I can take care of that
  • add @kendrickkay and @iancharest and whoever else as admin of the doc on read the docs - will try to add you
  • delete the wiki or replace it with a simple link to the doc - I don't have write access to this repo so one of you will have to do it

I will send an email with some of the typical doc formatting you could adopt if you so desired

@kendrickkay kendrickkay merged commit 7befbd8 into cvnlab:main Apr 29, 2022
@kendrickkay
Copy link
Member

OK, i replaced the wiki with a simple link to the new "readthedocs" site.

Please go ahead and do the remaining todo items listed above.

@kendrickkay
Copy link
Member

(PS: I have also majorly updated the wiki.md file on the repo, so I guess these changes will propagate once you link to the repo.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants