TP4 - Package Python complet avec tests, lint, docs et CI.
Project description
TP4 - Package Python (Poetry, Tests, Docs, CI)
Projet réalisé en suivant le tutoriel "Build Python Package".
Objectif
Construire un package Python complet avec :
- structure
src/ - tests unitaires (
pytest,pytest-cov) - lint/format (
ruff) + hookspre-commit - documentation Sphinx
- workflows GitHub Actions (tests + déploiement docs)
- préparation à la publication PyPI
Arborescence
.
├── .github/workflows/
│ ├── sphinx_doc.yaml
│ └── tests.yaml
├── docs/
│ ├── _static/
│ ├── _templates/
│ ├── Makefile
│ ├── conf.py
│ ├── index.rst
│ ├── make.bat
│ └── modules.rst
├── src/package_creation_tutorial/
│ ├── __init__.py
│ ├── main.py
│ └── string_ops.py
├── tests/
│ └── test_string_ops.py
├── .gitignore
├── .pre-commit-config.yaml
├── main.py
├── pyproject.toml
└── README.md
Prérequis
- Python 3.11+ (3.12 recommandé)
- Poetry
- Git
Installation de Poetry (exemple avec pipx) :
pipx install poetry
1) Build local du package
poetry install --with dev
poetry build
poetry run python main.py
Le script affiche :
- la chaîne originale
- sa version inversée
- le nombre de voyelles
- la chaîne avec capitalisation par mot
2) Tests et couverture
poetry run pytest
poetry run pytest --cov src/
3) Git / GitHub (rappel)
git init
git add .
git commit -m "initial project setup"
git remote add origin <URL_DU_REPO>
git push -u origin main
4) Ruff + pre-commit
poetry run ruff check --fix .
poetry run pre-commit install
poetry run pre-commit run --all-files
Configuration : .pre-commit-config.yaml avec hook ruff.
5) Documentation Sphinx
Build local :
cd docs
make html
Sous Windows :
cd docs
.\make.bat html
Fichier généré :
docs/build/html/index.html
6) GitHub Actions
Deux workflows sont fournis :
.github/workflows/tests.yaml: exécute les tests à chaque push/PR.github/workflows/sphinx_doc.yaml: build docs + publicationgh-pages
Configuration GitHub à faire
- Dans le dépôt GitHub :
Settings > Actions > General - Activer
Read and write permissionspourGITHUB_TOKEN - Dans
Settings > Pages, choisir la branchegh-pages
7) Publication sur PyPI
Configurer le token :
poetry config pypi-token.pypi <VOTRE_TOKEN>
Publier :
poetry build
poetry publish
Commandes utiles
poetry run python -m package_creation_tutorial.main
poetry run pytest -q
poetry run ruff check .
Auteur
Mehdi (TP4 DataViz)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file package_creation_mahdiznaidi-0.1.0.tar.gz.
File metadata
- Download URL: package_creation_mahdiznaidi-0.1.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.6 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
708ccdedd739e66bc8a87bd01642b72454d7395cb1c40a7fe2324e838aaa55c0
|
|
| MD5 |
b6a9246d2da8fe93ffc664124d856139
|
|
| BLAKE2b-256 |
d06c9a067cf6f6b5f057ff694c6edbee321b935cc790fbf2bd0efa8f63838a7a
|
File details
Details for the file package_creation_mahdiznaidi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: package_creation_mahdiznaidi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.2 CPython/3.11.6 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79a68afb79d9c9f23c47d579ee5a2fb9b3ab5261369de9cc6b658250854f5bce
|
|
| MD5 |
f55917f7f1714f3a14f1d70e4756b6db
|
|
| BLAKE2b-256 |
5884bc402c5b4189781ea8a1fafd28e8c1ef9559865cd47bde26c9040c1d85bc
|