spark: add Python env health check script
This commit is contained in:
1 parent
afdc563a9d
commit
c166bf1c0a
1 file changed
+53
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Python environment health check - verifies key packages are available."""
|
||||
|
||||
import sys
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def check_module(name):
|
||||
try:
|
||||
__import__(name)
|
||||
return {"status": "ok", "available": True}
|
||||
except ImportError as e:
|
||||
return {"status": "missing", "available": False, "error": str(e)}
|
||||
|
||||
def check_package(name, import_name=None):
|
||||
import_name = import_name or name
|
||||
try:
|
||||
mod = __import__(import_name)
|
||||
version = getattr(mod, '__version__', 'unknown')
|
||||
return {"status": "ok", "version": version, "available": True}
|
||||
except ImportError as e:
|
||||
return {"status": "missing", "available": False, "error": str(e)}
|
||||
|
||||
def main():
|
||||
results = {
|
||||
"python": {
|
||||
"status": "ok",
|
||||
"version": sys.version,
|
||||
"executable": sys.executable
|
||||
},
|
||||
"packages": {
|
||||
"json": check_module("json"),
|
||||
"subprocess": check_module("subprocess"),
|
||||
"datetime": check_module("datetime"),
|
||||
}
|
||||
}
|
||||
|
||||
all_ok = all(
|
||||
p.get("status") == "ok" or p.get("available", False)
|
||||
for p in results["packages"].values()
|
||||
)
|
||||
|
||||
output = {
|
||||
"all_ok": all_ok,
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
"components": results
|
||||
}
|
||||
|
||||
print(json.dumps(output, indent=2))
|
||||
sys.exit(0 if all_ok else 1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user