Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MDANSE
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Scientific Software
MDANSE
Commits
ba657e6c
Commit
ba657e6c
authored
10 years ago
by
eric pellegrini
Browse files
Options
Downloads
Patches
Plain Diff
Added examples for sphinx documentation
parent
7c19f587
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Doc/Template.py
+119
-0
119 additions, 0 deletions
Doc/Template.py
Doc/Template.rst
+5
-0
5 additions, 0 deletions
Doc/Template.rst
with
124 additions
and
0 deletions
Doc/Template.py
0 → 100644
+
119
−
0
View file @
ba657e6c
"""
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
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Doc/Template.rst
0 → 100644
+
5
−
0
View file @
ba657e6c
.. automodule:: Template
:members:
:undoc-members:
:inherited-members:
:show-inheritance:
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment