#!/usr/bin/env python3
from __future__ import annotations

import json
import platform
import sys
from pathlib import Path


def main():
    root = Path(__file__).resolve().parents[1]
    out_dir = root / "outputs/reproduced"
    out_dir.mkdir(parents=True, exist_ok=True)
    packages = {}
    for name in ["numpy", "pandas", "matplotlib", "sklearn", "scipy"]:
        try:
            mod = __import__(name)
            packages[name] = getattr(mod, "__version__", "unknown")
        except Exception as exc:
            packages[name] = f"NOT FOUND: {exc}"
    result = {
        "python": sys.version,
        "platform": platform.platform(),
        "packages": packages,
    }
    (out_dir / "environment_check.json").write_text(json.dumps(result, indent=2), encoding="utf-8")
    print(json.dumps(result, indent=2))


if __name__ == "__main__":
    main()
