Création d’une première documentation sphinx
Installer sphinx
sudo apt-get update
sudo apt-get install -f python3-sphinx
Créer un répertoire pour la documentation:
mkdir -p doc/sphinx
Créer un fichier requirments.txt pour les dépendances de la documentation:
touch ~/info_indus/info_indus_tutorial/doc/sphinx/requirements.txt
Ajouter les dépendances suivantes dans le fichier requirements.txt avec vscode:
mistune < 1.0.0
myst-parser
sphinx-copybutton
sphinx-tabs
sphinx_rtd_theme
sphinx-design
Installer les dépendances:
cd ~/info_indus/info_indus_tutorial/doc/sphinx
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Configurer la documentation
Initialiser la documentation avec les outils sphinx:
cd ~/info_indus/info_indus_tutorial/doc
sphinx-quickstart sphinx
Répondre aux questions posées par sphinx-quickstart.
Séparation source/build
Il est judicieux de séparer les sources du répertoire de build car du point de vue de la sauvegarde et du versionnement du projet avec git, on peut suivre tout ce qui se trouve dans le répertoire source.
On ne versionne en effet pas le répertoire de build, car il contient des éléments générés automatiquement donc qui peuvent être intégralement déduits de tous les autres fichiers versionnés.
On gagne ainsi beaucoup en quantité de données versionnées, c’est donc un gain de resources de temps de calcul et d’espace mémoire.
Nom du projet
Pour le nom du projet, il faut choisir un nom le plus court possible et qui soit aussi représentatif que possible du projet et de son usage.
Il est courant, par exemple, de préfixer une librairie python avec le préfix py.
Pour ce projet, la règle que nous allons choisir est la suivante: utilisez les initiales des personnes de votre groupe suivi de info_indus_tutorial. Par exemple, pour le groupe d” Amélie POULAIN, Jean DUPONT et Nikita TESTU, le nom du projet sera PaDjTn_info_indus_tutorial.
Examiner les fichiers créés par sphinx-quickstart du point de vue de git
Regarder avec git les nouveaux fichiers créés:
git status
Éditer les fichiers de configuration de sphinx
Modifier le fichier conf.py:
mettre-à-jour les extensions,
mettre-à-jour le theme html de la documentation (
html_theme),donner les options pour l’extension copybutton,
donner le chemin du fichier css
1# Configuration file for the Sphinx documentation builder.
2#
3# This file only contains a selection of the most common options. For a full
4# list see the documentation:
5# https://www.sphinx-doc.org/en/master/usage/configuration.html
6
7# -- Path setup --------------------------------------------------------------
8
9# If extensions (or modules to document with autodoc) are in another directory,
10# add these directories to sys.path here. If the directory is relative to the
11# documentation root, use os.path.abspath to make it absolute, like shown here.
12#
13# import os
14# import sys
15# sys.path.insert(0, os.path.abspath('.'))
16
17
18# -- Project information -----------------------------------------------------
19
20project = "Cours d'Informatique Industrielle avec ROS2"
21copyright = '2024, Manuel YGUEL'
22author = 'Manuel YGUEL'
23
24# The full version, including alpha/beta/rc tags
25release = '1.0.0'
26
27
28# -- General configuration ---------------------------------------------------
29
30# Add any Sphinx extension module names here, as strings. They can be
31# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
32# ones.
33extensions = [
34 "sphinx.ext.graphviz",
35 "sphinx.ext.ifconfig",
36 "sphinx.ext.intersphinx",
37 "sphinx_copybutton",
38 "sphinx_tabs.tabs",
39 "sphinx_rtd_theme",
40 "myst_parser",
41 "sphinx_design",
42]
43
44myst_enable_extensions = ["colon_fence"]
45
46# Add any paths that contain templates here, relative to this directory.
47templates_path = ['_templates']
48
49# The language for content autogenerated by Sphinx. Refer to documentation
50# for a list of supported languages.
51#
52# This is also used if you do content translation via gettext catalogs.
53# Usually you set "language" from the command line for these cases.
54language = 'fr'
55
56# List of patterns, relative to source directory, that match files and
57# directories to ignore when looking for source files.
58# This pattern also affects html_static_path and html_extra_path.
59exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
60source_suffix = [".rst", ".md"]
61
62
63# -- Options for HTML output -------------------------------------------------
64
65# The theme to use for HTML and HTML Help pages. See the documentation for
66# a list of builtin themes.
67#
68html_theme = 'sphinx_rtd_theme'
69
70html_sidebars = {
71 '**': [
72 'globaltoc.html', # Use the global TOC instead of the local one
73 'relations.html', # Adds links to the previous and next chapters
74 'searchbox.html', # Adds a search box
75 ]
76}
77
78# -- Options for copybutton extension ----------------------------------------
79copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
80copybutton_prompt_is_regexp = True
81
82# Add any paths that contain custom static files (such as style sheets) here,
83# relative to this directory. They are copied after the builtin static files,
84# so a file named "default.css" will overwrite the builtin "default.css".
85html_static_path = ['_static']
86
87html_css_files = [
88 "css/custom.css",
89]
Ajouter les fichiers créés par sphinx-quickstart:
Ajouter le fichier custom.css dans le répertoire _static/css:
mkdir -p ~/info_indus/info_indus_tutorial/doc/sphinx/source/_static/css
touch ~/info_indus/info_indus_tutorial/doc/sphinx/source/_static/css/custom.css
1/* Force line wraping in code instead of horizontal scrolling */
2pre {
3 white-space: pre-wrap !important;
4 word-break: break-all;
5}
6
7/* Add the possibility to underline text */
8.underline {
9 text-decoration: underline;
10}
11
12/* This allows the content to use most of the screen */
13@media (min-width: 1200px) {
14 .wy-nav-content {
15 max-width: 95%;
16 /* This allows the content to use most of the screen */
17 }
18}
19
20/** Allow caption from toctree to wrap nicely in sidebar */
21.wy-menu .caption-text {
22 white-space: normal;
23 word-wrap: break-word;
24 overflow-wrap: break-word;
25 line-height: 1.1;
26 /* Increase line height to prevent overlap */
27 display: block;
28 /* Ensure the element takes up full width */
29}
Créer la documentation
Depuis le répertoire sphinx faire:
cd ~/info_indus/info_indus_tutorial/doc/sphinx
make html
La documentation est un site statique html qui se trouve dans le répertoire build/html.
Le fichier index.html est la page d’accueil de la documentation.
Ouvrir la documentation avec un navigateur web, par exemple firefox:
firefox ~/info_indus/info_indus_tutorial/doc/sphinx/build/html/index.html
Sauvegarder la documentation avec git
Voir l’état de votre dépôt git:
git status
Ajouter les fichiers de la documentation:
cd ~/info_indus/info_indus_tutorial/doc/sphinx
git add source
git add Makefile make.bat requirements.txt
Fair le commit des modifications:
git commit -m "First commit of the documentation"