Fix _app_dir() pour Nuitka + crash log visible sans console
- _app_dir() utilise toujours Path(__file__).parent au lieu de dir() qui ne détecte pas __compiled__ dans une fonction - Ajout crash.log + messagebox en cas d'erreur fatale (même avec --windows-console-mode=disable) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -36,7 +36,21 @@ from tkinter import filedialog, messagebox, ttk
|
|||||||
try:
|
try:
|
||||||
import anonymizer_core_refactored_onnx as core
|
import anonymizer_core_refactored_onnx as core
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise SystemExit(f"Impossible d'importer le core ONNX : {e}")
|
_err_msg = f"Impossible d'importer le core ONNX : {e}"
|
||||||
|
# Écrire l'erreur dans un fichier log à côté du script/exe
|
||||||
|
try:
|
||||||
|
_log = Path(__file__).resolve().parent / "crash.log"
|
||||||
|
import traceback as _tb
|
||||||
|
_log.write_text(f"{_err_msg}\n\n{_tb.format_exc()}", encoding="utf-8")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
_r = tk.Tk(); _r.withdraw()
|
||||||
|
messagebox.showerror("Erreur d'import", _err_msg)
|
||||||
|
_r.destroy()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
raise SystemExit(_err_msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ner_manager_onnx import NerModelManager, NerThresholds
|
from ner_manager_onnx import NerModelManager, NerThresholds
|
||||||
@@ -69,11 +83,8 @@ APP_TITLE = "Pseudonymisation de PDF"
|
|||||||
APP_VERSION = "v5.0"
|
APP_VERSION = "v5.0"
|
||||||
|
|
||||||
def _app_dir() -> Path:
|
def _app_dir() -> Path:
|
||||||
"""Répertoire racine de l'application (compatible Nuitka onefile)."""
|
"""Répertoire racine de l'application (compatible Nuitka standalone)."""
|
||||||
# Nuitka onefile extrait dans un dossier temporaire
|
return Path(__file__).resolve().parent
|
||||||
if "__compiled__" in dir():
|
|
||||||
return Path(__file__).resolve().parent
|
|
||||||
return Path.cwd()
|
|
||||||
|
|
||||||
DEFAULT_CFG = _app_dir() / "config" / "dictionnaires.yml"
|
DEFAULT_CFG = _app_dir() / "config" / "dictionnaires.yml"
|
||||||
MODELS_DIR = _app_dir() / "models"
|
MODELS_DIR = _app_dir() / "models"
|
||||||
@@ -918,6 +929,27 @@ class App:
|
|||||||
# Point d'entrée
|
# Point d'entrée
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
root = tk.Tk()
|
try:
|
||||||
App(root)
|
root = tk.Tk()
|
||||||
root.mainloop()
|
App(root)
|
||||||
|
root.mainloop()
|
||||||
|
except Exception as exc:
|
||||||
|
import traceback, sys
|
||||||
|
err = traceback.format_exc()
|
||||||
|
# Écrire dans un fichier log à côté de l'exe
|
||||||
|
log_path = Path(__file__).resolve().parent / "crash.log"
|
||||||
|
try:
|
||||||
|
log_path.write_text(err, encoding="utf-8")
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
# Tenter d'afficher une messagebox (même sans console)
|
||||||
|
try:
|
||||||
|
import tkinter as _tk
|
||||||
|
_r = _tk.Tk()
|
||||||
|
_r.withdraw()
|
||||||
|
from tkinter import messagebox as _mb
|
||||||
|
_mb.showerror("Erreur fatale", f"L'application a planté :\n\n{exc}\n\nVoir crash.log")
|
||||||
|
_r.destroy()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
raise
|
||||||
|
|||||||
Reference in New Issue
Block a user