4.1. Garder ses modules à jour

Le module pip-review est un outil qui permet de lister les paquets Python installés et de vérifier s’ils sont à jour. Il permet également de mettre à jour les paquets obsolètes.

$ pip install pip-review                # Installe le module pip-review
Collecting pip-review
Downloading pip-review-1.3.0.tar.gz (6.6 kB)
Requirement already satisfied: packaging in /home/logos/.envs/sphinx/lib/python3.9/site-packages (from pip-review) (23.1)
Requirement already satisfied: pip in /home/logos/.envs/sphinx/lib/python3.9/site-packages (from pip-review) (20.3.4)
Building wheels for collected packages: pip-review
Building wheel for pip-review (setup.py) ... done
Created wheel for pip-review: filename=pip_review-1.3.0-py3-none-any.whl size=6545 sha256=eefd689a79524f0a2fae2a312939be2711b770cca39b781bd2dccdfae1ac0509
Stored in directory: /home/logos/.cache/pip/wheels/6c/35/b4/c8cf5319b0725e943bf60f2f3a4b01815ff7a3e0590c203d31
Successfully built pip-review
Installing collected packages: pip-review
Successfully installed pip-review-1.3.0
$ pip freeze > requirements.txt         # Sauvegarde les modules et versions installés
$ pip-review --auto                     # Mets à jour les modules installés
$ pip freeze > requirements.txt         # Sauvegarde la nouvelle configuration.

4.2. Magnifier son code

Le module black est un outil de formatage de code pour Python. Il permet de formater automatiquement le code Python en respectant les conventions de style PEP 8. Il est très populaire dans la communauté Python et est utilisé par de nombreux développeurs.

$ pip install black                # Installe le module black
Collecting black
Obtaining dependency information for black from https://files.pythonhosted.org/packages/09/16/ec8d08d2501a39258955c16fccb55a02faa6ef44190ca9fb0b88be0f494d/black-23.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata
Downloading black-23.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (63 kB)
    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 63.4/63.4 kB 2.1 MB/s eta 0:00:00
Collecting click>=8.0.0 (from black)
Obtaining dependency information for click>=8.0.0 from https://files.pythonhosted.org/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl.metadata
Downloading click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting mypy-extensions>=0.4.3 (from black)
Using cached mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Requirement already satisfied: packaging>=22.0 in /home/logos/.envs/sphinx/lib/python3.9/site-packages (from black) (23.1)
Collecting pathspec>=0.9.0 (from black)
Obtaining dependency information for pathspec>=0.9.0 from https://files.pythonhosted.org/packages/b4/2a/9b1be29146139ef459188f5e420a66e835dda921208db600b7037093891f/pathspec-0.11.2-py3-none-any.whl.metadata
Downloading pathspec-0.11.2-py3-none-any.whl.metadata (19 kB)
Requirement already satisfied: platformdirs>=2 in /home/logos/.envs/sphinx/lib/python3.9/site-packages (from black) (3.10.0)
Collecting tomli>=1.1.0 (from black)
Using cached tomli-2.0.1-py3-none-any.whl (12 kB)
Requirement already satisfied: typing-extensions>=3.10.0.0 in /home/logos/.envs/sphinx/lib/python3.9/site-packages (from black) (4.7.1)
Downloading black-23.7.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.7 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 14.3 MB/s eta 0:00:00
Downloading click-8.1.7-py3-none-any.whl (97 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.9/97.9 kB 6.7 MB/s eta 0:00:00
Downloading pathspec-0.11.2-py3-none-any.whl (29 kB)
Installing collected packages: tomli, pathspec, mypy-extensions, click, black
Successfully installed black-23.7.0 click-8.1.7 mypy-extensions-1.0.0 pathspec-0.11.2 tomli-2.0.1
$ find ./ -name "*.py" -exec black "{}" \;
reformatted bin/pass.py

All done! ✨ 🍰 ✨
1 file reformatted.
reformatted source/conf.py

All done! ✨ 🍰 ✨
1 file reformatted.

4.3. Documenter son code

$ pip install sphinx                # Installe le module sphinx