"""q00_env.py: the software environment the plan will build in, read from the installed tools (not typed)."""
import re, subprocess, sys
import sklearn, numpy, pandas, matplotlib

sys.path.insert(0, "/home/claude/mill/code")
from vals import Values

V = Values(path="/home/claude/mill/phase3/outputs/values3.json", script="q00_env.py")
E = lambda s: {"population": "this workspace", "filter": "installed software", "statistic": s}
tex = subprocess.run(["tex", "--version"], capture_output=True, text=True).stdout
m = re.search(r"\((TeX Live \d{4})", tex)
V.set("env_texlive", m.group(1) if m else "not found", "text", E("TeX distribution as reported by tex --version"), kind="text")
V.set("env_pdflatex", "present" if subprocess.run(["which", "pdflatex"], capture_output=True).returncode == 0 else "absent", "text", E("pdflatex on the path"), kind="text")
V.set("env_python", sys.version.split()[0], "text", E("Python version"), kind="text")
V.set("env_sklearn", sklearn.__version__, "text", E("scikit-learn version"), kind="text")
V.set("env_numpy", numpy.__version__, "text", E("NumPy version"), kind="text")
V.set("env_pandas", pandas.__version__, "text", E("pandas version"), kind="text")
V.set("env_matplotlib", matplotlib.__version__, "text", E("Matplotlib version"), kind="text")
V.save()
print("q00_env: registered", len([k for k in V.v if V.v[k]["source"] == "q00_env.py"]), "values")
