Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.


Commandes essentielles

Environnement (pixi)

ActionCommande
Initialiser un projetpixi init
Ajouter une dépendancepixi add numpy
Ajouter dans une featurepixi add --feature linter ruff
Mettre à jour le lockpixi update
Exécuter une commandepixi run python script.py
Exécuter dans un envpixi run -e linter ruff check .
Ouvrir un shellpixi shell

Packaging

ActionCommande
Installer en mode éditablepip install -e .
Construire une sdistpython -m build --sdist
Construire une wheelpython -m build --wheel
Publier sur PyPitwine upload dist/*
Publier sur test PyPitwine upload -r testpypi dist/*

Linter & Typage

ActionCommande
pylintpylint mon_package/
ruff (vérification)ruff check mon_package/
ruff (correction auto)ruff check --fix mon_package/
ruff (formatage)ruff format mon_package/
mypy (typage)mypy mon_package/

Tests

ActionCommande
Lancer tous les testspytest tests/
Tests rapides uniquementpytest tests/ -m "not long"
Avec couverturepytest --cov mon_package tests/
Générer images référencepytest --mpl-generate-path=tests/baseline
Tests avec comparaisonpytest --mpl tests/

Documentation

ActionCommande
Initialiser Sphinxsphinx-quickstart
Construire la doc HTMLcd doc && make html

Git & CI

ActionCommande
Installer pre-commitpre-commit install
Lancer pre-commitpre-commit run --all-files

Structure type d’un projet Python

mon-projet/
├── pyproject.toml          # Métadonnées, dépendances, config des outils
├── pixi.toml               # Environnement pixi
├── pixi.lock               # Lock file (généré)
├── LICENSE                 # Licence du projet
├── README.md               # Présentation
├── .gitignore
├── .pre-commit-config.yaml # Hooks pre-commit
├── .github/workflows/      # CI GitHub Actions
├── mon_package/            # Code source
│   ├── __init__.py
│   ├── version.py
│   └── ...
├── tests/                  # Tests
│   └── baseline/           # Images référence (pytest-mpl)
├── doc/                    # Documentation Sphinx
│   ├── source/
│   │   ├── conf.py
│   │   └── index.md
│   └── Makefile
├── recipes/                # Recette conda
│   └── meta.yaml
└── notebooks/              # Notebooks Jupyter

FAQ : erreurs fréquentes et solutions

ModuleNotFoundError: No module named 'mon_package'

Le package n’est pas installé dans l’environnement actif.

pip install -e .          # mode éditable
# ou
pixi install

403 Client Error sur PyPi

Token invalide ou expiré. Régénérez-le sur pypi.org/manage/account/token/ et mettez à jour ~/.pypirc.

pylint: command not found dans pixi

pylint est installé dans une feature, pas dans l’environnement par défaut.

pixi run -e linter pylint mon_package/

ruff: Failed to parse

Vérifiez que target-version dans pyproject.toml correspond à votre version Python.

tests/baseline image mismatch

L’image générée ne correspond plus à la référence.

pytest --mpl-generate-path=tests/baseline tests/

conda-build ne trouve pas les sources

Le répertoire .pixi perturbe conda-build.

conda build --croot /tmp/conda-build recipes/

pre-commit ne se déclenche pas

pre-commit install

Glossaire

package
Répertoire contenant du code Python avec un __init__.py, installable via pip.
pyproject.toml
Fichier de configuration standard (PEP 621) décrivant le projet, ses dépendances, et la configuration des outils.
sdist
Archive source (.tar.gz). L’installation nécessite une étape de build.
wheel
Archive binaire pré-construite (.whl). Installation rapide, pas de build.
entry point
Permet d’appeler une fonction Python depuis le terminal (ex: splinart).
channel
Dépôt de paquets conda (ex: conda-forge).
feature (pixi)
Groupe de dépendances optionnel (ex: linter, tests).
lock file
Fichier décrivant l’arbre exact des dépendances résolues. Garantit la reproductibilité.
CI
Automatisation qui exécute tests, linters à chaque modification (GitHub Actions).
linting
Analyse statique du code pour détecter problèmes de style et erreurs potentielles.
typage statique
Annotations optionnelles indiquant les types attendus. Vérifiées par mypy.
editable install
Installation en mode développement (pip install -e .). Modifications visibles immédiatement.
noarch
Paquet conda indépendant de l’architecture. S’installe sur tous les OS.

Pour aller plus loin