File size: 11,007 Bytes
bff1348
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Makefile β€” Picarones
# Usage : make <cible>
# Cibles principales : install, test, demo, serve, build, build-exe, docker-build, clean

.PHONY: all install install-dev install-all test test-cov lint demo serve \
        build build-exe docker-build docker-run docker-compose-up clean help

PYTHON     := python3
PIP        := pip
VENV       := .venv
VENV_BIN   := $(VENV)/bin
PICARONES  := $(VENV_BIN)/picarones
PYTEST     := $(VENV_BIN)/pytest
PACKAGE    := picarones

# Couleurs
BOLD  := \033[1m
GREEN := \033[32m
CYAN  := \033[36m
RESET := \033[0m

# ──────────────────────────────────────────────────────────────────
# Aide
# ──────────────────────────────────────────────────────────────────

help: ## Affiche cette aide
	@echo ""
	@echo "$(BOLD)Picarones β€” Commandes disponibles$(RESET)"
	@echo ""
	@grep -E '^[a-zA-Z_-]+:.*## ' $(MAKEFILE_LIST) \
	  | sort \
	  | awk 'BEGIN {FS = ":.*## "}; {printf "  $(CYAN)%-18s$(RESET) %s\n", $$1, $$2}'
	@echo ""

all: install test  ## Installer et tester

# ──────────────────────────────────────────────────────────────────
# Installation
# ──────────────────────────────────────────────────────────────────

$(VENV):
	$(PYTHON) -m venv $(VENV)

install: $(VENV)  ## Installe Picarones en mode Γ©ditable (dΓ©pendances de base)
	$(VENV_BIN)/pip install --upgrade pip
	$(VENV_BIN)/pip install -e .
	@echo "$(GREEN)βœ“ Installation de base terminΓ©e$(RESET)"
	@echo "  Activez l'environnement : source $(VENV)/bin/activate"

install-dev: $(VENV)  ## Installe avec les dΓ©pendances de dΓ©veloppement (tests, lint)
	$(VENV_BIN)/pip install --upgrade pip
	$(VENV_BIN)/pip install -e ".[dev]"
	@echo "$(GREEN)βœ“ Installation dev terminΓ©e$(RESET)"

install-web: $(VENV)  ## Installe avec l'interface web (FastAPI + uvicorn)
	$(VENV_BIN)/pip install --upgrade pip
	$(VENV_BIN)/pip install -e ".[web,dev]"
	@echo "$(GREEN)βœ“ Installation web terminΓ©e$(RESET)"

install-all: $(VENV)  ## Installe avec tous les extras (web, HuggingFace, dev)
	$(VENV_BIN)/pip install --upgrade pip
	$(VENV_BIN)/pip install -e ".[web,hf,dev]"
	@echo "$(GREEN)βœ“ Installation complΓ¨te terminΓ©e$(RESET)"

# ──────────────────────────────────────────────────────────────────
# Tests
# ──────────────────────────────────────────────────────────────────

test:  ## Lance la suite de tests complète
	$(PYTEST) tests/ -q --tb=short
	@echo "$(GREEN)βœ“ Tests terminΓ©s$(RESET)"

test-cov:  ## Tests avec rapport de couverture HTML
	$(PYTEST) tests/ --cov=$(PACKAGE) --cov-report=html --cov-report=term-missing -q
	@echo "$(GREEN)βœ“ Rapport de couverture : htmlcov/index.html$(RESET)"

test-fast:  ## Tests rapides uniquement (exclut les tests lents)
	$(PYTEST) tests/ -q --tb=short -x

test-sprint9:  ## Tests Sprint 9 uniquement
	$(PYTEST) tests/test_sprint9_packaging.py -v

# ──────────────────────────────────────────────────────────────────
# QualitΓ© du code
# ──────────────────────────────────────────────────────────────────

lint:  ## VΓ©rifie le style du code (ruff si disponible, sinon flake8)
	@if command -v ruff > /dev/null 2>&1; then \
	  ruff check $(PACKAGE)/ tests/; \
	elif $(VENV_BIN)/python -m ruff --version > /dev/null 2>&1; then \
	  $(VENV_BIN)/python -m ruff check $(PACKAGE)/ tests/; \
	elif command -v flake8 > /dev/null 2>&1; then \
	  flake8 $(PACKAGE)/ tests/ --max-line-length=100 --ignore=E501,W503; \
	else \
	  echo "Aucun linter disponible (installez ruff : pip install ruff)"; \
	fi

typecheck:  ## VΓ©rification de types avec mypy (si installΓ©)
	@$(VENV_BIN)/python -m mypy $(PACKAGE)/ --ignore-missing-imports --no-strict-optional 2>/dev/null \
	  || echo "mypy non installΓ© : pip install mypy"

# ──────────────────────────────────────────────────────────────────
# DΓ©monstration
# ──────────────────────────────────────────────────────────────────

demo:  ## Génère un rapport de démonstration complet (rapport_demo.html)
	$(PICARONES) demo --docs 12 --output rapport_demo.html \
	  --with-history --with-robustness
	@echo "$(GREEN)βœ“ Rapport demo : rapport_demo.html$(RESET)"
	@echo "  Ouvrez : file://$(PWD)/rapport_demo.html"

demo-json:  ## Génère rapport demo + export JSON
	$(PICARONES) demo --docs 12 --output rapport_demo.html --json-output resultats_demo.json
	@echo "$(GREEN)βœ“ Rapport : rapport_demo.html | JSON : resultats_demo.json$(RESET)"

demo-history:  ## DΓ©monstration du suivi longitudinal
	$(PICARONES) history --demo --regression

demo-robustness:  ## DΓ©monstration de l'analyse de robustesse
	mkdir -p /tmp/picarones_demo_corpus
	$(PICARONES) robustness \
	  --corpus /tmp/picarones_demo_corpus \
	  --engine tesseract \
	  --demo \
	  --degradations noise,blur,rotation

# ──────────────────────────────────────────────────────────────────
# Serveur web
# ──────────────────────────────────────────────────────────────────

serve:  ## Lance l'interface web locale (http://localhost:8000)
	$(PICARONES) serve --host 127.0.0.1 --port 8000

serve-public:  ## Lance le serveur en mode public (0.0.0.0:8000)
	$(PICARONES) serve --host 0.0.0.0 --port 8000

serve-dev:  ## Lance le serveur en mode dΓ©veloppement (rechargement automatique)
	$(PICARONES) serve --reload --verbose

# ──────────────────────────────────────────────────────────────────
# Build & packaging
# ──────────────────────────────────────────────────────────────────

build:  ## Construit la distribution Python (wheel + sdist)
	$(VENV_BIN)/pip install --upgrade build
	$(VENV_BIN)/python -m build
	@echo "$(GREEN)βœ“ Distribution : dist/$(RESET)"

build-exe:  ## Génère un exécutable standalone avec PyInstaller
	@echo "$(CYAN)Construction de l'exΓ©cutable standalone…$(RESET)"
	$(VENV_BIN)/pip install pyinstaller
	$(VENV_BIN)/pyinstaller picarones.spec --noconfirm
	@echo "$(GREEN)βœ“ ExΓ©cutable : dist/picarones/$(RESET)"

build-exe-onefile:  ## Génère un exécutable unique (plus lent au démarrage)
	$(VENV_BIN)/pip install pyinstaller
	$(VENV_BIN)/pyinstaller picarones.spec --noconfirm --onefile
	@echo "$(GREEN)βœ“ ExΓ©cutable : dist/picarones$(RESET)"

# ──────────────────────────────────────────────────────────────────
# Docker
# ──────────────────────────────────────────────────────────────────

docker-build:  ## Construit l'image Docker Picarones
	docker build -t picarones:latest -t picarones:1.0.0 .
	@echo "$(GREEN)βœ“ Image Docker : picarones:latest$(RESET)"

docker-run:  ## Lance Picarones dans Docker (http://localhost:8000)
	docker run --rm -p 8000:8000 \
	  -e OPENAI_API_KEY="$${OPENAI_API_KEY:-}" \
	  -e ANTHROPIC_API_KEY="$${ANTHROPIC_API_KEY:-}" \
	  -e MISTRAL_API_KEY="$${MISTRAL_API_KEY:-}" \
	  -v "$(PWD)/corpus:/app/corpus:ro" \
	  picarones:latest

docker-compose-up:  ## Lance Picarones + Ollama avec Docker Compose
	docker compose up -d
	@echo "$(GREEN)βœ“ Services dΓ©marrΓ©s$(RESET)"
	@echo "  Picarones : http://localhost:8000"
	@echo "  Ollama    : http://localhost:11434"

docker-compose-down:  ## ArrΓͺte les services Docker Compose
	docker compose down

docker-compose-logs:  ## Affiche les logs Docker Compose
	docker compose logs -f picarones

# ──────────────────────────────────────────────────────────────────
# Nettoyage
# ──────────────────────────────────────────────────────────────────

clean:  ## Supprime les fichiers gΓ©nΓ©rΓ©s (cache, build, dist)
	find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete 2>/dev/null || true
	find . -type f -name "*.pyo" -delete 2>/dev/null || true
	find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
	rm -rf dist/ build/ .eggs/ htmlcov/ .coverage .pytest_cache/
	@echo "$(GREEN)βœ“ Nettoyage terminΓ©$(RESET)"

clean-all: clean  ## Supprime aussi l'environnement virtuel
	rm -rf $(VENV)/
	@echo "$(GREEN)βœ“ Environnement virtuel supprimΓ©$(RESET)"

# ──────────────────────────────────────────────────────────────────
# Utilitaires
# ──────────────────────────────────────────────────────────────────

info:  ## Affiche les informations de version Picarones
	$(PICARONES) info

engines:  ## Liste les moteurs OCR disponibles
	$(PICARONES) engines

history-demo:  ## Affiche l'historique de dΓ©monstration
	$(PICARONES) history --demo --regression

changelog:  ## Affiche le CHANGELOG
	@cat CHANGELOG.md | head -80

version:  ## Affiche la version courante
	@grep -m1 'version' pyproject.toml | awk '{print $$3}' | tr -d '"'