Skip to main content

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) + hooks pre-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 + publication gh-pages

Configuration GitHub à faire

  1. Dans le dépôt GitHub : Settings > Actions > General
  2. Activer Read and write permissions pour GITHUB_TOKEN
  3. Dans Settings > Pages, choisir la branche gh-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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

package_creation_mahdiznaidi-0.1.0.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

package_creation_mahdiznaidi-0.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file package_creation_mahdiznaidi-0.1.0.tar.gz.

File metadata

File hashes

Hashes for package_creation_mahdiznaidi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 708ccdedd739e66bc8a87bd01642b72454d7395cb1c40a7fe2324e838aaa55c0
MD5 b6a9246d2da8fe93ffc664124d856139
BLAKE2b-256 d06c9a067cf6f6b5f057ff694c6edbee321b935cc790fbf2bd0efa8f63838a7a

See more details on using hashes here.

File details

Details for the file package_creation_mahdiznaidi-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for package_creation_mahdiznaidi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79a68afb79d9c9f23c47d579ee5a2fb9b3ab5261369de9cc6b658250854f5bce
MD5 f55917f7f1714f3a14f1d70e4756b6db
BLAKE2b-256 5884bc402c5b4189781ea8a1fafd28e8c1ef9559865cd47bde26c9040c1d85bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page