Spaces:
Running
Running
import argparse | |
from sys import exit | |
import subprocess | |
from pathlib import Path | |
import os | |
import tempfile | |
from src.generic_eval import main as gmain | |
def eval_script(path: Path): | |
status = None | |
stdout = None | |
stderr = None | |
exit_code = None | |
try: | |
# 创建临时目录用于Go缓存 | |
with tempfile.TemporaryDirectory() as temp_dir: | |
# 设置Go环境变量 | |
env = os.environ.copy() | |
env["GOCACHE"] = os.path.join(temp_dir, "go-build") | |
env["GOPATH"] = os.path.join(temp_dir, "gopath") | |
build = subprocess.run(["go", "test", path], | |
env=env, | |
timeout=30, | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE) | |
stdout = build.stdout.decode("utf-8", errors="ignore") | |
stderr = build.stderr.decode("utf-8", errors="ignore") | |
exit_code = build.returncode | |
# write to stderr just so that we can redirect stdout to a csv | |
if "[setup failed]" in stdout or "[build failed]" in stdout: | |
status = "SyntaxError" | |
elif "FAIL" in stdout: | |
status = "Exception" | |
else: | |
status = "OK" | |
except subprocess.TimeoutExpired: | |
status = "Timeout" | |
return { | |
"status": status, | |
"exit_code": exit_code, | |
"stdout": stdout, | |
"stderr": stderr, | |
} | |
if __name__ == "__main__": | |
gmain(eval_script, 'Go', '.go') | |