|
""" |
|
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): |
|
|
|
temp_dir = tempfile.mkdtemp(prefix="clojure_home_") |
|
env = os.environ.copy() |
|
env["XDG_CONFIG_HOME"] = temp_dir |
|
env["XDG_DATA_HOME"] = temp_dir |
|
env["XDG_CACHE_HOME"] = temp_dir |
|
|
|
|
|
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: |
|
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.") |
|
|