Projet

Général

Profil

DocumentationCodeBonnesPratiques » Historique » Version 18

Gwenael Remond, 18/01/2013 09:10

1 1 Emmanuel GARETTE
h1. DocumentationCodeBonnesPratiques
2 1 Emmanuel GARETTE
3 18 Gwenael Remond
**cette page concerne la documentation développeur**
4 18 Gwenael Remond
(voir aussi [[TestsCodeBonnesPratiques]] pour les autres bonnes pratiques développeur)
5 18 Gwenael Remond
6 1 Emmanuel GARETTE
h2. Généralité
7 1 Emmanuel GARETTE
8 1 Emmanuel GARETTE
* La documentation technique doit être en anglais.
9 5 Gérald Schwartzmann
* Elle est placée dans les docstrings du code.
10 1 Emmanuel GARETTE
11 1 Emmanuel GARETTE
h2. Description du module
12 1 Emmanuel GARETTE
13 12 Daniel Dehennin
La docstring du module est placée en haut du fichier juste après le "shebang":https://fr.wikipedia.org/wiki/Shebang, la déclaration d’"encodage des caractères":https://fr.wikipedia.org/wiki/Codage_de_caract%C3%A8res et la licence du code.
14 2 Gwenael Remond
15 1 Emmanuel GARETTE
<pre>
16 12 Daniel Dehennin
#!/usr/bin/python
17 12 Daniel Dehennin
# -*- coding: utf-8 -*-
18 12 Daniel Dehennin
#
19 16 Emmanuel GARETTE
##########################################################################
20 16 Emmanuel GARETTE
# <nom du projet>
21 16 Emmanuel GARETTE
# Copyright © 2012 Pôle de compétences EOLE <eole@ac-dijon.fr>
22 14 Daniel Dehennin
#
23 16 Emmanuel GARETTE
# License CeCILL:
24 16 Emmanuel GARETTE
#  * in french: http://www.cecill.info/licences/Licence_CeCILL_V2-fr.html
25 16 Emmanuel GARETTE
#  * in english http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
26 16 Emmanuel GARETTE
##########################################################################
27 2 Gwenael Remond
</pre>
28 2 Gwenael Remond
29 11 Daniel Dehennin
La docstring doit contenir :
30 1 Emmanuel GARETTE
* description rapide en une phrase du module ;
31 1 Emmanuel GARETTE
* description avancée qui explique le rôle du module ;
32 1 Emmanuel GARETTE
* des exemples simples d'utilisation.
33 1 Emmanuel GARETTE
34 1 Emmanuel GARETTE
Les exemples peuvent être un prompt :
35 1 Emmanuel GARETTE
36 1 Emmanuel GARETTE
<pre>
37 1 Emmanuel GARETTE
    >>> is_locked()
38 1 Emmanuel GARETTE
    True
39 1 Emmanuel GARETTE
</pre>
40 1 Emmanuel GARETTE
41 1 Emmanuel GARETTE
ou une portion de code :
42 1 Emmanuel GARETTE
43 1 Emmanuel GARETTE
<pre>
44 1 Emmanuel GARETTE
    ::
45 1 Emmanuel GARETTE
46 1 Emmanuel GARETTE
        from toto.titi import is_locked
47 1 Emmanuel GARETTE
48 1 Emmanuel GARETTE
        toto()
49 1 Emmanuel GARETTE
        is_locked()
50 1 Emmanuel GARETTE
</pre>
51 1 Emmanuel GARETTE
52 1 Emmanuel GARETTE
h2. Docstring des méthodes
53 1 Emmanuel GARETTE
54 3 Gwenael Remond
Seules les méthodes publiques (qui ne commencent pas par "_") seront mises dans la documentation (mais les méthodes privées sont aussi à documenter).
55 1 Emmanuel GARETTE
56 1 Emmanuel GARETTE
La docstring doit contenir :
57 1 Emmanuel GARETTE
58 1 Emmanuel GARETTE
* description rapide en une phrase de la méthode ;
59 1 Emmanuel GARETTE
* si nécessaire une description avancée qui explique le rôle du module ;
60 1 Emmanuel GARETTE
* si nécessaire des exemples simples d'utilisation.
61 1 Emmanuel GARETTE
* les paramètres de la façon suivante (xxx étant le nom du paramètre et yyyyyy la description) :
62 1 Emmanuel GARETTE
63 1 Emmanuel GARETTE
<pre>
64 1 Emmanuel GARETTE
    :param xxx: yyyyyy
65 1 Emmanuel GARETTE
</pre>
66 1 Emmanuel GARETTE
67 1 Emmanuel GARETTE
Si nécessaire les valeurs de retour (yyyyyy étant la description) :
68 1 Emmanuel GARETTE
69 1 Emmanuel GARETTE
<pre>
70 1 Emmanuel GARETTE
    :return: yyyyyy
71 1 Emmanuel GARETTE
</pre>
72 1 Emmanuel GARETTE
73 4 Gwenael Remond
plus d'info sur la syntaxe des docstrings: http://sphinx-doc.org/domains.html#info-field-lists
74 4 Gwenael Remond
75 1 Emmanuel GARETTE
h2. Docstring des classes
76 1 Emmanuel GARETTE
77 10 Gwenael Remond
comme pour la docstring des modules (mais sans la licence)
78 8 Gwenael Remond
79 8 Gwenael Remond
h2. Tips
80 8 Gwenael Remond
81 8 Gwenael Remond
il est possible de faire un lien portant directement sur le redmine de deux manières :
82 8 Gwenael Remond
83 8 Gwenael Remond
<pre> 
84 8 Gwenael Remond
85 8 Gwenael Remond
:issue:`410` 
86 8 Gwenael Remond
87 8 Gwenael Remond
</pre> 
88 8 Gwenael Remond
89 8 Gwenael Remond
est un lien qui porte directement sur la demande 410
90 8 Gwenael Remond
91 8 Gwenael Remond
et
92 8 Gwenael Remond
93 8 Gwenael Remond
<pre>
94 8 Gwenael Remond
95 8 Gwenael Remond
 :eole:`/projects/creole/wiki/Lock24`
96 8 Gwenael Remond
97 8 Gwenael Remond
</pre>
98 8 Gwenael Remond
99 8 Gwenael Remond
qui est simplement un raccourci vers http://dev-eole.ac-dijon.fr/projects/creole/wiki/Lock24
100 17 Daniel Dehennin
101 17 Daniel Dehennin
h2. Exemples
102 17 Daniel Dehennin
103 17 Daniel Dehennin
Plusieurs fichiers sources ont reçu une attention assez particulière sur la documentation :
104 17 Daniel Dehennin
105 17 Daniel Dehennin
- python-pyeole:source:pyeole/decorator.py
106 17 Daniel Dehennin
- python-pyeole:source:pyeole/log.py
107 17 Daniel Dehennin
- python-pyeole:source:pyeole/lock.py