issue205:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| issue205:python [2024/06/01 10:20] – créée auntiee | issue205:python [2024/06/12 15:27] (Version actuelle) – andre_domenech | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | More Mysteries of the Sphinx | + | **More Mysteries of the Sphinx |
| Greetings fellow Sentient Lifeforms. Beaming yet again from somewhere in time and space, I come again to, hopefully, provide more well needed information. (If you are not a Sentient Lifeform, I do not intend to withhold this from you, so feel free to attempt to read this.) | Greetings fellow Sentient Lifeforms. Beaming yet again from somewhere in time and space, I come again to, hopefully, provide more well needed information. (If you are not a Sentient Lifeform, I do not intend to withhold this from you, so feel free to attempt to read this.) | ||
| - | This month' | + | This month' |
| - | 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. | + | 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. | ||
| Creating the docstrings that are needed to do this is very simple, but you need to remember to use the docstrings in every function, no matter how simple. If you don’t, you’ll probably have to go back and update the source file. | Creating the docstrings that are needed to do this is very simple, but you need to remember to use the docstrings in every function, no matter how simple. If you don’t, you’ll probably have to go back and update the source file. | ||
| Ligne 11: | Ligne 18: | ||
| So, it all starts with your source code. If you use PAGE to create your GUI program, you don’t need to do anything to the PAGE .tcl file or the Python GUI.py file. The only file you need to concern yourself with is the support.py file. | So, it all starts with your source code. If you use PAGE to create your GUI program, you don’t need to do anything to the PAGE .tcl file or the Python GUI.py file. The only file you need to concern yourself with is the support.py file. | ||
| - | 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 |
| The docstring is simply a section of your source code that starts and ends with three double quotes and in between is pretty much free-form information. However, for Sphinx to grab the information, | The docstring is simply a section of your source code that starts and ends with three double quotes and in between is pretty much free-form information. However, for Sphinx to grab the information, | ||
| Ligne 29: | Ligne 45: | ||
| Then what the function returns: | Then what the function returns: | ||
| - | :return: description of the return value | + | :return: description of the return value** |
| - | If there is more than one parameter, simply repeat the param and type keys. | + | 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. | ||
| For more information on Docstrings, you can follow this link https:// | For more information on Docstrings, you can follow this link https:// | ||
| Ligne 43: | Ligne 78: | ||
| One of the best things about the program is for the user to have the ability to change themes at any time to any theme in the theme folder. Of course, these are all .tcl themes. Use the load_tcl_themes function to generate a list of all of the themes, then load this into a TCombobox values property. Then bind the virtual **<< | One of the best things about the program is for the user to have the ability to change themes at any time to any theme in the theme folder. Of course, these are all .tcl themes. Use the load_tcl_themes function to generate a list of all of the themes, then load this into a TCombobox values property. Then bind the virtual **<< | ||
| - | Now we describe the function using the .. py: | + | Now we describe the function using the .. 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). | + | 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). | ||
| Here (next page, top right) is how it will look in your HTML file. | Here (next page, top right) is how it will look in your HTML file. | ||
| Ligne 58: | Ligne 108: | ||
| The most important line is the one that starts with | The most important line is the one that starts with | ||
| + | |||
| + | 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() | 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. | ||
| The other important part is the extensions section. You will need to have all four lines in the list. | The other important part is the extensions section. You will need to have all four lines in the list. | ||
| 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… | ||
| - | API | + | 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 | ||
| ====== | ====== | ||
| Ligne 95: | Ligne 178: | ||
| Notice that the only line in bold is the one that adds the api.rst file, and this is the one you need to add. You don’t have to include the .rst extension. | Notice that the only line in bold is the one that adds the api.rst file, and this is the one you need to add. You don’t have to include the .rst extension. | ||
| - | 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, | ||
| - | And when you click on the hyperlink in red, you will be directed to the api listing. | + | **And when you click on the hyperlink in red, you will be directed to the api listing. |
| You can see that the two functions that I included with the .. py: | You can see that the two functions that I included with the .. py: | ||
| Ligne 106: | Ligne 210: | ||
| You can create a special .rst file that holds all the ..py: | You can create a special .rst file that holds all the ..py: | ||
| - | 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.** |
| - | Conclusion | + | 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 | ||
| If you are getting a number of errors when you do your build, the first thing that you should look at is the directive formatting and the line(s) following the directive. Sphinx is VERY picky about formatting and white space. It’s usually something very simple. | If you are getting a number of errors when you do your build, the first thing that you should look at is the directive formatting and the line(s) following the directive. Sphinx is VERY picky about formatting and white space. It’s usually something very simple. | ||
| Ligne 118: | Ligne 231: | ||
| I also included the generated HTML file in the code/ | I also included the generated HTML file in the code/ | ||
| - | 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.1717230052.txt.gz · Dernière modification : 2024/06/01 10:20 de auntiee
