# --- Initialisation : chemins du depot, helpers WSL (patron Tweety-02d / Tweety-5e) ---
# Ce labo est certifiant de bout en bout : sa seule dependance d'execution est le lake sibling
# `formal_logic_lean`. Pas de JVM ici -- le versant Java de la modale est le labo Tweety-3b.
import json
import os
import pathlib
import shutil
import subprocess
import sys
import tempfile
TWEETY_DIR = pathlib.Path.cwd()
if TWEETY_DIR.name != "Tweety":
# execution hors du dossier Tweety : retour au chemin canonique, puis remontee des parents
candidat = pathlib.Path("MyIA.AI.Notebooks") / "SymbolicAI" / "Tweety"
if not candidat.is_dir():
for parent in pathlib.Path.cwd().resolve().parents:
if (parent / candidat).is_dir():
candidat = parent / candidat
break
if candidat.is_dir():
os.chdir(candidat)
TWEETY_DIR = pathlib.Path.cwd()
assert TWEETY_DIR.name == "Tweety", f"dossier Tweety introuvable depuis {TWEETY_DIR}"
LAKE_DIR = (TWEETY_DIR.parent / "Lean" / "formal_logic_lean").resolve()
assert (LAKE_DIR / "lakefile.lean").is_file(), f"lake introuvable : {LAKE_DIR}"
def to_wsl(p):
"""Chemin Windows -> chemin WSL /mnt/..."""
win = p.resolve().as_posix()
return "/mnt/" + win[0].lower() + win[2:]
def run_wsl(command, timeout):
"""Commande dans WSL, echec explicite si le binaire manque (patron Tweety-5e)."""
if shutil.which("wsl") is None:
raise RuntimeError(
"les certificats Lean passent par WSL (`wsl -e bash -lc`) : binaire `wsl` "
"introuvable. Ce labo exige un hote Windows + WSL -- reparer l'environnement "
"(regle F), aucun contournement."
)
return subprocess.run(
["wsl", "-e", "bash", "-lc", command],
capture_output=True, text=True, encoding="utf-8", errors="replace",
timeout=timeout,
)
# Chemins RELATIFS a la racine du depot : une sortie de cellule ne doit pas
# figer le chemin d'une machine (les carnets jumeaux 02d/02e n'en portent aucun).
RACINE = TWEETY_DIR.parents[2] # <racine>\MyIA.AI.Notebooks\SymbolicAI\Tweety
print("Serie Tweety :", TWEETY_DIR.relative_to(RACINE).as_posix())
print("Lake certifiant :", LAKE_DIR.relative_to(RACINE).as_posix())
print("WSL :", "present" if shutil.which("wsl") else "absent")
print("Python :", sys.version.split()[0])Serie Tweety : MyIA.AI.Notebooks/SymbolicAI/Tweety
Lake certifiant : MyIA.AI.Notebooks/SymbolicAI/Lean/formal_logic_lean
WSL : present
Python : 3.13.14
