MultiPLE-Evaluator / src /eval_clj.py
dongsheng's picture
Upload 48 files
41e79e2 verified
"""
Evaluates a generated Clojure program (.clj).
"""
import os
import tempfile
from pathlib import Path
from src.safe_subprocess import run
from src.libeval import run_without_exn
def eval_script(path: Path):
# Create environment with a writable temporary directory for Clojure cache
temp_dir = tempfile.mkdtemp(prefix="clojure_home_")
env = os.environ.copy()
env["XDG_CONFIG_HOME"] = temp_dir # Set XDG_CONFIG_HOME for Clojure cache
env["XDG_DATA_HOME"] = temp_dir # Set XDG_DATA_HOME for Clojure data
env["XDG_CACHE_HOME"] = temp_dir # Set XDG_CACHE_HOME for caches
# Run Clojure with the custom environment
result = run(
["clojure", "-J-Dclojure.main.report=stderr", "-M", str(path)],
env=env
)
if result.timeout:
status = "Timeout"
elif result.exit_code != 0:
status = "Exception"
elif "\n0 failures, 0 errors.\n" in result.stdout:
status = "OK"
else: # test failure
status = "Exception"
return {
"status": status,
"exit_code": result.exit_code,
"stdout": result.stdout,
"stderr": result.stderr,
}
if __name__ == "__main__":
print("This module is not meant to be executed directly.")