Skip to content

Commit d6136da

Browse files
bayesflowsfumitoh
authored andcommitted
Create Makefile for virtual development environment
1 parent 97aa623 commit d6136da

File tree

2 files changed

+205
-0
lines changed

2 files changed

+205
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ __pycache__/
1010
temp.py
1111
temp[1-9].py
1212

13+
# virtual environments
14+
venv_lifelib/
15+
1316
# due to using tox and pytest
1417
.tox
1518
.cache

Makefile

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
# Makefile pour le projet lifelib
2+
# Automatisation de l'environnement de développement et des tâches courantes
3+
4+
.PHONY: help venv install install-dev install-test clean clean-all test test-cov lint format check build dist
5+
6+
# Variables
7+
PYTHON := python3
8+
VENV := venv_lifelib
9+
BIN := $(VENV)/bin
10+
PYTHON_VENV := $(BIN)/python
11+
PIP := $(BIN)/pip
12+
13+
# Détection de l'OS pour activation
14+
ifeq ($(OS),Windows_NT)
15+
ACTIVATE := $(VENV)/Scripts/activate
16+
else
17+
ACTIVATE := $(BIN)/activate
18+
endif
19+
20+
# Couleurs pour l'affichage
21+
BLUE := \033[0;34m
22+
GREEN := \033[0;32m
23+
YELLOW := \033[0;33m
24+
RED := \033[0;31m
25+
NC := \033[0m # No Color
26+
27+
# Cible par défaut
28+
.DEFAULT_GOAL := help
29+
30+
help: ## Afficher cette aide
31+
@echo "$(BLUE)═══════════════════════════════════════════════════════════$(NC)"
32+
@echo "$(BLUE) Makefile pour lifelib - Gestion de l'environnement$(NC)"
33+
@echo "$(BLUE)═══════════════════════════════════════════════════════════$(NC)"
34+
@echo ""
35+
@echo "$(GREEN)Commandes disponibles :$(NC)"
36+
@echo ""
37+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(YELLOW)%-20s$(NC) %s\n", $$1, $$2}'
38+
@echo ""
39+
@echo "$(BLUE)Exemples d'utilisation :$(NC)"
40+
@echo " make venv # Créer l'environnement virtuel"
41+
@echo " make install-dev # Installer en mode développement"
42+
@echo " make test # Lancer les tests"
43+
@echo " make format # Formater le code"
44+
@echo ""
45+
46+
venv: ## Créer l'environnement virtuel Python
47+
@echo "$(BLUE)Création de l'environnement virtuel...$(NC)"
48+
@if [ ! -d "$(VENV)" ]; then \
49+
$(PYTHON) -m venv $(VENV); \
50+
echo "$(GREEN)✓ Environnement virtuel créé dans $(VENV)$(NC)"; \
51+
else \
52+
echo "$(YELLOW)⚠ L'environnement virtuel existe déjà$(NC)"; \
53+
fi
54+
@echo ""
55+
@echo "$(GREEN)Pour activer l'environnement virtuel :$(NC)"
56+
@echo " source $(ACTIVATE)"
57+
58+
install: venv ## Installer le package en mode production
59+
@echo "$(BLUE)Installation du package en mode production...$(NC)"
60+
@$(PIP) install --upgrade pip setuptools wheel
61+
@$(PIP) install -e .
62+
@echo "$(GREEN)✓ Installation terminée$(NC)"
63+
64+
install-dev: venv ## Installer le package en mode développement (avec dépendances dev)
65+
@echo "$(BLUE)Installation du package en mode développement...$(NC)"
66+
@$(PIP) install --upgrade pip setuptools wheel
67+
@$(PIP) install -e ".[dev]"
68+
@echo "$(GREEN)✓ Installation développement terminée$(NC)"
69+
@echo ""
70+
@echo "$(GREEN)Dépendances installées :$(NC)"
71+
@echo " - modelx (runtime)"
72+
@echo " - pytest, pytest-cov, pytest-xdist (tests)"
73+
@echo " - pandas, numpy, openpyxl (tests)"
74+
@echo " - flake8, black, isort (dev)"
75+
76+
install-test: venv ## Installer le package en mode test uniquement
77+
@echo "$(BLUE)Installation du package en mode test...$(NC)"
78+
@$(PIP) install --upgrade pip setuptools wheel
79+
@$(PIP) install -e ".[test]"
80+
@echo "$(GREEN)✓ Installation test terminée$(NC)"
81+
82+
upgrade: venv ## Mettre à jour toutes les dépendances
83+
@echo "$(BLUE)Mise à jour des dépendances...$(NC)"
84+
@$(PIP) install --upgrade pip setuptools wheel
85+
@$(PIP) install --upgrade -e ".[dev]"
86+
@echo "$(GREEN)✓ Dépendances mises à jour$(NC)"
87+
88+
test: ## Lancer les tests avec pytest
89+
@echo "$(BLUE)Lancement des tests...$(NC)"
90+
@$(BIN)/pytest -v --cov=lifelib --cov-report=term-missing
91+
@echo "$(GREEN)✓ Tests terminés$(NC)"
92+
93+
test-cov: ## Lancer les tests avec rapport de couverture HTML
94+
@echo "$(BLUE)Lancement des tests avec rapport de couverture...$(NC)"
95+
@$(BIN)/pytest --cov=lifelib --cov-report=html --cov-report=term --cov-report=xml
96+
@echo "$(GREEN)✓ Rapport de couverture généré dans htmlcov/index.html$(NC)"
97+
98+
test-fast: ## Lancer les tests en parallèle (rapide)
99+
@echo "$(BLUE)Lancement des tests en parallèle...$(NC)"
100+
@$(BIN)/pytest -n auto -v
101+
@echo "$(GREEN)✓ Tests terminés$(NC)"
102+
103+
lint: ## Vérifier le code avec flake8
104+
@echo "$(BLUE)Vérification du code avec flake8...$(NC)"
105+
@$(BIN)/flake8 lifelib --count --select=E9,F63,F7,F82 --show-source --statistics
106+
@$(BIN)/flake8 lifelib --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
107+
@echo "$(GREEN)✓ Vérification terminée$(NC)"
108+
109+
format: ## Formater le code avec black et isort
110+
@echo "$(BLUE)Formatage du code avec black et isort...$(NC)"
111+
@$(BIN)/black lifelib
112+
@$(BIN)/isort lifelib
113+
@echo "$(GREEN)✓ Code formaté$(NC)"
114+
115+
check: ## Vérifier le formatage sans modifier les fichiers
116+
@echo "$(BLUE)Vérification du formatage...$(NC)"
117+
@$(BIN)/black --check lifelib
118+
@$(BIN)/isort --check-only lifelib
119+
@echo "$(GREEN)✓ Vérification terminée$(NC)"
120+
121+
check-all: lint check ## Vérifier le code et le formatage (lint + check)
122+
@echo "$(GREEN)✓ Toutes les vérifications sont terminées$(NC)"
123+
124+
build: ## Construire le package (sdist et wheel)
125+
@echo "$(BLUE)Construction du package...$(NC)"
126+
@$(PYTHON_VENV) -m pip install --upgrade build
127+
@$(PYTHON_VENV) -m build
128+
@echo "$(GREEN)✓ Package construit dans dist/$(NC)"
129+
130+
dist: clean build ## Nettoyer et construire le package pour distribution
131+
132+
clean: ## Nettoyer les fichiers générés (cache, build, etc.)
133+
@echo "$(BLUE)Nettoyage des fichiers générés...$(NC)"
134+
@rm -rf build/
135+
@rm -rf dist/
136+
@rm -rf *.egg-info
137+
@rm -rf .pytest_cache/
138+
@rm -rf .coverage
139+
@rm -rf htmlcov/
140+
@rm -rf .tox/
141+
@find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
142+
@find . -type f -name "*.pyc" -delete
143+
@find . -type f -name "*.pyo" -delete
144+
@find . -type f -name "*.pyd" -delete
145+
@find . -type f -name ".coverage.*" -delete
146+
@echo "$(GREEN)✓ Nettoyage terminé$(NC)"
147+
148+
clean-all: clean ## Nettoyer tout y compris l'environnement virtuel
149+
@echo "$(BLUE)Suppression de l'environnement virtuel...$(NC)"
150+
@rm -rf $(VENV)
151+
@echo "$(GREEN)✓ Environnement virtuel supprimé$(NC)"
152+
153+
info: ## Afficher les informations sur l'environnement
154+
@echo "$(BLUE)═══════════════════════════════════════════════════════════$(NC)"
155+
@echo "$(BLUE) Informations sur l'environnement$(NC)"
156+
@echo "$(BLUE)═══════════════════════════════════════════════════════════$(NC)"
157+
@echo ""
158+
@echo "$(GREEN)Python :$(NC)"
159+
@which $(PYTHON) && $(PYTHON) --version || echo "Python non trouvé"
160+
@echo ""
161+
@if [ -d "$(VENV)" ]; then \
162+
echo "$(GREEN)Environnement virtuel :$(NC) $(VENV) (actif)"; \
163+
echo "$(GREEN)Version Python :$(NC)"; \
164+
$(PYTHON_VENV) --version; \
165+
echo ""; \
166+
echo "$(GREEN)Packages installés :$(NC)"; \
167+
$(PIP) list; \
168+
else \
169+
echo "$(YELLOW)Environnement virtuel non créé$(NC)"; \
170+
echo "Lancez 'make venv' pour le créer"; \
171+
fi
172+
173+
shell: ## Ouvrir un shell dans l'environnement virtuel
174+
@echo "$(BLUE)Ouverture d'un shell dans l'environnement virtuel...$(NC)"
175+
@echo "$(YELLOW)Pour quitter : tapez 'exit'$(NC)"
176+
@. $(ACTIVATE) && exec $(SHELL)
177+
178+
tox: venv ## Lancer les tests avec tox (tous les environnements)
179+
@echo "$(BLUE)Installation et lancement de tox...$(NC)"
180+
@$(PIP) install tox
181+
@$(BIN)/tox
182+
183+
tox-lint: venv ## Lancer uniquement le linting avec tox
184+
@echo "$(BLUE)Lancement du linting avec tox...$(NC)"
185+
@$(PIP) install tox
186+
@$(BIN)/tox -e lint
187+
188+
init: install-dev ## Initialiser complètement l'environnement de développement
189+
@echo ""
190+
@echo "$(GREEN)═══════════════════════════════════════════════════════════$(NC)"
191+
@echo "$(GREEN) Environnement de développement prêt !$(NC)"
192+
@echo "$(GREEN)═══════════════════════════════════════════════════════════$(NC)"
193+
@echo ""
194+
@echo "$(YELLOW)Pour activer l'environnement virtuel :$(NC)"
195+
@echo " source $(ACTIVATE)"
196+
@echo ""
197+
@echo "$(YELLOW)Commandes utiles :$(NC)"
198+
@echo " make test # Lancer les tests"
199+
@echo " make format # Formater le code"
200+
@echo " make lint # Vérifier le code"
201+
@echo " make help # Voir toutes les commandes"
202+
@echo ""

0 commit comments

Comments
 (0)