issue205:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| issue205:python [2024/06/03 07:10] – d52fr | issue205:python [2024/06/12 15:27] (Version actuelle) – andre_domenech | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| This month' | This month' | ||
| + | |||
| + | D' | ||
| + | |||
| + | Bonjour à tous les êtres vivants sensibles. Rayonnant une fois de plus de quelque part dans le temps et l' | ||
| + | |||
| + | L' | ||
| + | |||
| **I created a dummy program that really does nothing much but has functions that have Python Docstrings that can be used by Sphinx to “automatically document” the functions in the generated HTML or EPUB files. | **I created a dummy program that really does nothing much but has functions that have Python Docstrings that can be used by Sphinx to “automatically document” the functions in the generated HTML or EPUB files. | ||
| Ligne 12: | Ligne 19: | ||
| One other thing to note, I’m using the bizstyle theme for Sphinx. If you decide to use a different Sphinx theme, your document won’t match the images that I’ve included here.** | One other thing to note, I’m using the bizstyle theme for Sphinx. If you decide to use a different Sphinx theme, your document won’t match the images that I’ve included here.** | ||
| + | |||
| + | J'ai créé un programme factice qui ne fait pas grand-chose, | ||
| + | |||
| + | La création des docstrings nécessaires à cette fin est très simple, mais vous devez vous rappeler d' | ||
| + | |||
| + | Tout commence donc avec votre code source. Si vous utilisez PAGE pour créer votre programme de GUI, vous n'avez rien à faire dans le fichier PAGE .tcl ou dans le fichier Python GUI.py. Le seul fichier dont vous devez vous préoccuper est le fichier support.py. | ||
| + | |||
| + | Une autre chose à noter, j' | ||
| + | |||
| **The docstring | **The docstring | ||
| Ligne 30: | Ligne 46: | ||
| :return: description of the return value** | :return: description of the return value** | ||
| + | |||
| + | La docstring | ||
| + | |||
| + | La docstring est simplement une section de votre code source qui commence et se termine par trois guillemets doubles et entre les deux se trouvent des informations libres. Cependant, pour que Sphinx puisse saisir l' | ||
| + | |||
| + | Bien sûr, la première ligne est la définition de la fonction. Ensuite, nous commençons la docstring avec les trois doubles guillemets. | ||
| + | |||
| + | La ligne suivante est une description de l' | ||
| + | |||
| + | :param {parameter name}: | ||
| + | |||
| + | :type {parameter name}: | ||
| + | |||
| + | ... | ||
| + | |||
| + | Ensuite, ce que la fonction renvoie : | ||
| + | |||
| + | :return: description de la valeur retournée | ||
| + | |||
| **If there is more than one parameter, simply repeat the param and type keys. | **If there is more than one parameter, simply repeat the param and type keys. | ||
| Ligne 44: | Ligne 79: | ||
| Now we describe the function using the .. py: | Now we describe the function using the .. py: | ||
| + | |||
| + | S'il y a plus d'un paramètre, il suffit de répéter les clés param et type. | ||
| + | |||
| + | Pour plus d' | ||
| + | |||
| + | Le faire manuellement | ||
| + | |||
| + | Bien entendu, vous pouvez documenter manuellement vos fonctions et méthodes. Je vais créer une entrée « factice » pour un document **Sphinx** fictif. | ||
| + | |||
| + | Voici la description que je mettrais dans le fichier fictif index.rst... | ||
| + | |||
| + | L'un des aspects les plus intéressants du programme est que l' | ||
| + | |||
| + | Maintenant, nous décrivons la fonction en utilisant la directive ... py: | ||
| + | |||
| **You can see that this is very similar to the docstring information that I suggested you place into the source code, but manually entered into the index.rst Sphinx file (right). | **You can see that this is very similar to the docstring information that I suggested you place into the source code, but manually entered into the index.rst Sphinx file (right). | ||
| Ligne 60: | Ligne 110: | ||
| sys.path.append()** | sys.path.append()** | ||
| + | |||
| + | Vous pouvez voir qu'il s'agit d'une information très similaire à la docstring que je vous ai suggéré de placer dans le code source, mais saisie manuellement dans le fichier index.rst de Sphinx (à droite). | ||
| + | |||
| + | Voici (page suivante, en haut à droite) à quoi cela ressemblera dans votre fichier HTML. | ||
| + | C'est beaucoup de travail, surtout si le code a déjà été documenté à l'aide des docstrings. | ||
| + | |||
| + | |||
| + | Le faire automatiquement | ||
| + | |||
| + | Afin de profiter des capacités de documentation automatique de Sphinx, vous devez faire un peu de préparation. Vous devrez modifier le fichier conf.py et ajouter au moins un fichier .rst supplémentaire dans le dossier / | ||
| + | |||
| + | Les modifications doivent être apportées au fichier conf.py. Ces lignes (à droite) doivent être placées aux alentours de la ligne 16. | ||
| + | |||
| + | La ligne la plus importante est celle qui commence par | ||
| + | |||
| + | sys.path.append() | ||
| + | |||
| **This is the fully qualified path to your source code. You don’t need to enter the filename(s) at this point, just the path. | **This is the fully qualified path to your source code. You don’t need to enter the filename(s) at this point, just the path. | ||
| Ligne 72: | Ligne 139: | ||
| Adding an Autosummary | Adding an Autosummary | ||
| + | |||
| You need to create an extra .rst file named something like “api.rst”. In it you place just a few lines…** | You need to create an extra .rst file named something like “api.rst”. In it you place just a few lines…** | ||
| + | |||
| + | Voici le chemin d' | ||
| + | |||
| + | L' | ||
| + | |||
| + | Il ne vous reste plus qu'à ajouter une ligne à votre fichier index.rst pour chaque fonction que vous voulez que Sphinx documente. | ||
| + | |||
| + | .. autofonction: | ||
| + | |||
| + | Bien sûr, vous pouvez ajouter du texte avant ou après cette ligne, mais voici à quoi ressemblera la sortie. (J'ai inclus la première ligne, juste pour améliorer la fluidité). Voir l' | ||
| + | |||
| + | Ajouter un résumé automatique //d52fr : à traiter comme un titre// | ||
| + | |||
| + | Vous devez créer un fichier .rst supplémentaire nommé quelque chose comme « api.rst ». Dans ce fichier, vous placez quelques lignes... | ||
| + | |||
| **API | **API | ||
| Ligne 96: | Ligne 179: | ||
| When you run your next build, you will see the addition to the bottom of the main page…** | When you run your next build, you will see the addition to the bottom of the main page…** | ||
| + | |||
| + | API | ||
| + | ====== | ||
| + | |||
| + | .. autosummary:: | ||
| + | |||
| + | : | ||
| + | |||
| + | | ||
| + | |||
| + | Le dernier ajout à votre fichier index.rst doit indiquer à Sphinx d' | ||
| + | |||
| + | .. toctree:: | ||
| + | |||
| + | : | ||
| + | |||
| + | : | ||
| + | |||
| + | api | ||
| + | |||
| + | Remarquez que la seule ligne en gras est celle qui ajoute le fichier api.rst et c'est celui que vous devez ajouter. Vous n'avez pas besoin d' | ||
| + | |||
| + | Lorsque vous lancerez votre prochaine compilation, | ||
| Ligne 105: | Ligne 211: | ||
| One word of warning here. If you are using Formiko as your .rst editor, you will end up with a number of warnings in the preview window. These are usually a “System Message: Error/3” warning. You can usually ignore these messages, since they refer to unknown directives. I’m fairly certain that the folks at Formiko will get these added or addressed in the near future.** | One word of warning here. If you are using Formiko as your .rst editor, you will end up with a number of warnings in the preview window. These are usually a “System Message: Error/3” warning. You can usually ignore these messages, since they refer to unknown directives. I’m fairly certain that the folks at Formiko will get these added or addressed in the near future.** | ||
| + | |||
| + | Et lorsque vous cliquez sur l' | ||
| + | |||
| + | Vous pouvez voir que les deux fonctions que j'ai incluses avec la directive ... py: | ||
| + | |||
| + | Vous pouvez créer un fichier .rst spécial qui contient toutes les directives ... py: | ||
| + | |||
| + | Un mot d' | ||
| + | |||
| **Conclusion | **Conclusion | ||
| Ligne 117: | Ligne 232: | ||
| Until next time, as always; stay safe, healthy, positive and creative!** | Until next time, as always; stay safe, healthy, positive and creative!** | ||
| + | |||
| + | Conclusion | ||
| + | |||
| + | Si vous obtenez un certain nombre d' | ||
| + | |||
| + | J'ai créé un dépôt comme je le fais souvent. J'ai inclus les fichiers Sphinx index.rst et conf.py pour que vous puissiez facilement avoir une référence aux informations de ce mois. | ||
| + | |||
| + | Le dépôt est situé à l' | ||
| + | |||
| + | J'ai également inclus le fichier HTML généré dans le fichier code/ | ||
| + | |||
| + | Jusqu' | ||
| + | |||
| + | // p 30, lignes noires dans l' | ||
| + | |||
| + | **Now we can include more descriptive text and/or a snippet of the | ||
| + | function. | ||
| + | Here is the code that will actually switch the theme to the user selection...** | ||
| + | |||
| + | Maintenant, | ||
| + | Voici le code qui va vraiment changé le thème pour celui choisi par l' | ||
| + | |||
issue205/python.1717391421.txt.gz · Dernière modification : 2024/06/03 07:10 de d52fr
