File size: 1,872 Bytes
aac75d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Script pour corriger automatiquement les problèmes de lint du projet.
Usage: python scripts/fix_lint.py
"""
import subprocess
import sys
from pathlib import Path


def run_command(cmd, description):
    """Exécute une commande et affiche le résultat."""
    print(f"\n{'=' * 60}")
    print(f"🔧 {description}")
    print(f"{'=' * 60}")

    result = subprocess.run(cmd, shell=True, capture_output=True, text=True)

    if result.stdout:
        print(result.stdout)
    if result.stderr:
        print(result.stderr, file=sys.stderr)

    return result.returncode


def main():
    """Corrige tous les problèmes de lint."""
    project_root = Path(__file__).parent.parent

    print(f"📁 Projet : {project_root}")

    # 1. Formater avec Black
    returncode = run_command(
        f"cd {project_root} && .venv/bin/black ml_model/ tests/ examples/ --line-length 88",
        "Formatage avec Black",
    )

    # 2. Trier les imports avec isort
    returncode += run_command(
        f"cd {project_root} && .venv/bin/python -m isort ml_model/ tests/ examples/ --profile black",
        "Tri des imports avec isort",
    )

    # 3. Vérifier avec Flake8
    returncode += run_command(
        f"cd {project_root} && .venv/bin/python -m flake8 ml_model/ tests/ examples/ --max-line-length=88 --extend-ignore=E203,W503",
        "Vérification avec Flake8",
    )

    # 4. Lancer les tests
    returncode += run_command(
        f"cd {project_root} && .venv/bin/python -m pytest tests/test_basic.py -v",
        "Exécution des tests",
    )

    print(f"\n{'=' * 60}")
    if returncode == 0:
        print("✅ Tous les checks passent !")
    else:
        print("⚠️  Certains problèmes subsistent. Vérifiez les logs ci-dessus.")
    print(f"{'=' * 60}\n")

    return returncode


if __name__ == "__main__":
    sys.exit(main())