#!/usr/bin/env python3
import subprocess
import venv
from pathlib import Path
import sys

_DIR = Path(__file__).parent
_PROGRAM_DIR = _DIR.parent
_VENV_DIR = _PROGRAM_DIR / ".venv"
_MODULE_DIR = _PROGRAM_DIR / "linux_voice_assistant"

_LINT_DIRS = [_MODULE_DIR]

if _VENV_DIR.exists():
    context = venv.EnvBuilder().ensure_directories(_VENV_DIR)
    python_exe = context.env_exe
else:
    python_exe = "python3"

# Überprüfen, ob --auto angegeben wurde
auto_fix = "--auto" in sys.argv

if auto_fix:
    # Automatisch formatieren
    subprocess.check_call([python_exe, "-m", "isort"] + _LINT_DIRS)
else:
    # Nur prüfen, ob Formatierung korrekt ist
    subprocess.check_call([python_exe, "-m", "isort"] + _LINT_DIRS + ["--check", "--diff"])
