#!/usr/bin/env python3 """ Environment verification script. Produces a manifest file with verifiable facts. """ import subprocess import hashlib import json import sys from pathlib import Path def get_sha256(text: str) -> str: return hashlib.sha256(text.encode()).hexdigest() def run_cmd(cmd: str) -> tuple[str, str]: result = subprocess.run(cmd, shell=True, capture_output=True, text=True) return result.stdout.strip(), result.stderr.strip() def main(): manifest = {} # Python version py_ver, _ = run_cmd("python3 --version") manifest["python_version"] = py_ver manifest["python_version_hash"] = get_sha256(py_ver) # Pip version pip_ver, _ = run_cmd("pip --version") manifest["pip_version"] = pip_ver manifest["pip_version_hash"] = get_sha256(pip_ver) # Python executable path py_path, _ = run_cmd("which python3") manifest["python_path"] = py_path manifest["python_path_hash"] = get_sha256(py_path) # Verify pip module is importable try: import pip manifest["pip_module_importable"] = True manifest["pip_module_version"] = pip.__version__ manifest["pip_module_version_hash"] = get_sha256(pip.__version__) except ImportError as e: manifest["pip_module_importable"] = False manifest["pip_import_error"] = str(e) # Write manifest output_path = Path("/root/.hermes/wizard-outputs/spark/manifest.json") with open(output_path, "w") as f: json.dump(manifest, f, indent=2) print(f"Manifest written to {output_path}") print(json.dumps(manifest, indent=2)) # Verify expected values assert "Python 3.14.7" in manifest["python_version"], f"Unexpected Python version: {manifest['python_version']}" assert manifest["python_path"].endswith("python3"), f"Unexpected Python path: {manifest['python_path']}" assert manifest["pip_module_importable"] == True, "pip module not importable" print("\nAll verifications passed!", file=sys.stderr) return 0 if __name__ == "__main__": sys.exit(main())