System Software Design (API) Documentation

Holds discussions about Wimborne Model Town's River System Design and any relevant drawings.

Relevant documents are available at https://wmtprojectsforum.altervista.org ... les/Design
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

System Software Design (API) Documentation

Post by hamishmb »

Hi all,

I'm thinking of using something called Sphinx to write our documentation for the software, because it's fast, easy, and generates easy-to-read, industry-standard documentation. I need to do some more research but from what I can tell it seems like a perfect match for our situation. It actually makes me feel excited about writing documentation (!) :P

Terry, here are some examples of the docstring syntax and the resulting documentation. Are you happy with this?

Syntax (taken from http://thomas-cokelaer.info/tutorials/s ... ython.html:

Code: Select all

"""This module illustrates how to write your docstring in OpenAlea
and other projects related to OpenAlea."""

__license__ = "Cecill-C"
__revision__ = " $Id: actor.py 1586 2009-01-30 15:56:25Z cokelaer $ "
__docformat__ = 'reStructuredText'


class MainClass1(object):
    """This class docstring shows how to use sphinx and rst syntax

    The first line is brief explanation, which may be completed with 
    a longer one. For instance to discuss about its methods. The only
    method here is :func:`function1`'s. The main idea is to document
    the class and methods's arguments with 

    - **parameters**, **types**, **return** and **return types**::

          :param arg1: description
          :param arg2: description
          :type arg1: type description
          :type arg1: type description
          :return: return description
          :rtype: the return type description

    - and to provide sections such as **Example** using the double commas syntax::

          :Example:

          followed by a blank line !

      which appears as follow:

      :Example:

      followed by a blank line

    - Finally special sections such as **See Also**, **Warnings**, **Notes**
      use the sphinx syntax (*paragraph directives*)::

          .. seealso:: blabla
          .. warnings also:: blabla
          .. note:: blabla
          .. todo:: blabla

    .. note::
        There are many other Info fields but they may be redundant:
            * param, parameter, arg, argument, key, keyword: Description of a
              parameter.
            * type: Type of a parameter.
            * raises, raise, except, exception: That (and when) a specific
              exception is raised.
            * var, ivar, cvar: Description of a variable.
            * returns, return: Description of the return value.
            * rtype: Return type.

    .. note::
        There are many other directives such as versionadded, versionchanged,
        rubric, centered, ... See the sphinx documentation for more details.

    Here below is the results of the :func:`function1` docstring.

    """

    def function1(self, arg1, arg2, arg3):
        """returns (arg1 / arg2) + arg3

        This is a longer explanation, which may include math with latex syntax
        :math:`\\alpha`.
        Then, you need to provide optional subsection in this order (just to be
        consistent and have a uniform documentation. Nothing prevent you to
        switch the order):

          - parameters using ``:param <name>: <description>``
          - type of the parameters ``:type <name>: <description>``
          - returns using ``:returns: <description>``
          - examples (doctest)
          - seealso using ``.. seealso:: text``
          - notes using ``.. note:: text``
          - warning using ``.. warning:: text``
          - todo ``.. todo:: text``

        **Advantages**:
         - Uses sphinx markups, which will certainly be improved in future
           version
         - Nice HTML output with the See Also, Note, Warnings directives


        **Drawbacks**:
         - Just looking at the docstring, the parameter, type and  return
           sections do not appear nicely

        :param arg1: the first value
        :param arg2: the first value
        :param arg3: the first value
        :type arg1: int, float,...
        :type arg2: int, float,...
        :type arg3: int, float,...
        :returns: arg1/arg2 +arg3
        :rtype: int, float

        :Example:

        >>> import template
        >>> a = template.MainClass1()
        >>> a.function1(1,1,1)
        2

        .. note:: can be useful to emphasize
            important feature
        .. seealso:: :class:`MainClass2`
        .. warning:: arg2 must be non-zero.
        .. todo:: check that arg2 is non zero.
        """
        return arg1/arg2 + arg3




if __name__ == "__main__":
    import doctest
    doctest.testmod()
Resulting documentation: http://thomas-cokelaer.info/tutorials/s ... ython.html, section 2.1.

You can (and we should) theme the output to make it look pretty and easy to read, so it can look like any of these: http://www.sphinx-doc.org/en/stable/theming.html, 'Builtin Themes' section.

Is it alright with all of you if I go ahead with this?

Hamish
Last edited by hamishmb on 03/11/2017, 11:12, edited 1 time in total.
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: System Software Design Documentation

Post by TerryJC »

hamishmb wrote:I'm thinking of using something called Sphinx to write our documentation for the software, because it's fast, easy, and generates easy-to-read, industry-standard documentation. I need to do some more research but from what I can tell it seems like a perfect match for our situation. It actually makes me feel excited about writing documentation (!) :P

Terry, here are some examples of the docstring syntax and the resulting documentation. Are you happy with this?
Yes.
hamishmb wrote:You can (and we should) theme the output to make it look pretty and easy to read, so it can look like any of these: http://www.sphinx-doc.org/en/stable/theming.html, 'Builtin Themes' section.
I would suggest the 'classic' theme because it is styled like the Python documentation.
hamishmb wrote:Is it alright with all of you if I go ahead with this?
It's fine by me.
Terry
Penri
Posts: 1284
Joined: 18/05/2017, 21:28

Re: System Software Design Documentation

Post by Penri »

Hello

I have not objections.

Hwyl

Penri
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: System Software Design Documentation

Post by hamishmb »

Okay, cool. I was going to suggest the classic theme too :)

I'll make a start on it this afternoon then.
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: System Software Design Documentation

Post by hamishmb »

Okay, I've made some significant progress despite having to learn the basics of how to write reStructuredText, and some import errors I spent around an hour fixing :P

Attached is what I've come up with so far (extract, then navigate inside and open index.html in your browser).

What do you think?

Hamish
Attachments
documentation_early_preview.tar.gz
(137.11 KiB) Downloaded 94 times
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: System Software Design Documentation

Post by TerryJC »

Hamish,

I like that. We can provide this in a folder labelled documentation and in the higher level design documents, simply put a generic statement that points the user to the correct place.
Terry
Penri
Posts: 1284
Joined: 18/05/2017, 21:28

Re: System Software Design Documentation

Post by Penri »

Hamish

It looks good to me too.


Penri
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: System Software Design Documentation

Post by hamishmb »

Excellent :)

I of course have a view to finishing the initial documentation (it will be on-going) very soon, but we'll have to see how that ties in with other stuff :)

Worst case scenario it should be done by the 15th or so.

Hamish
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: System Software Design (API) Documentation

Post by hamishmb »

It's going much faster than I thought :)

I've done most of it now, but not quite finished. Attached is what we have now. Terry, shall I keep you a co-author of this documentation, because I imagine you'll be fairly instrumental in the way it's laid out and defined?

Hamish
Attachments
documentation_preview_2.tar.gz
(144.56 KiB) Downloaded 92 times
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: System Software Design (API) Documentation

Post by hamishmb »

Note: After uploading I realised the documentation for the constructors wasn't getting added. I've fixed it now, but ^ that version doesn't have it.
Hamish
Post Reply