Spaces:
Sleeping
Sleeping
朱东升
commited on
Commit
·
fa01b9b
1
Parent(s):
43675d0
requirements update24
Browse files- src/containerized_eval.py +1 -0
- src/eval_go.py +8 -34
src/containerized_eval.py
CHANGED
@@ -72,6 +72,7 @@ def eval_string_script(language, program):
|
|
72 |
with tempfile.NamedTemporaryFile(suffix=file_ext, delete=True) as f:
|
73 |
f.write(program.encode("utf-8"))
|
74 |
f.flush()
|
|
|
75 |
result = eval_script(Path(f.name))
|
76 |
# Only save the first 2K of output from the running program. Any futher
|
77 |
# output is very likely an exceptionally long stack trace or a long
|
|
|
72 |
with tempfile.NamedTemporaryFile(suffix=file_ext, delete=True) as f:
|
73 |
f.write(program.encode("utf-8"))
|
74 |
f.flush()
|
75 |
+
print(Path(f.name))
|
76 |
result = eval_script(Path(f.name))
|
77 |
# Only save the first 2K of output from the running program. Any futher
|
78 |
# output is very likely an exceptionally long stack trace or a long
|
src/eval_go.py
CHANGED
@@ -2,8 +2,6 @@ import argparse
|
|
2 |
from sys import exit
|
3 |
import subprocess
|
4 |
from pathlib import Path
|
5 |
-
import os
|
6 |
-
import tempfile
|
7 |
from .generic_eval import main as gmain
|
8 |
|
9 |
|
@@ -12,42 +10,16 @@ def eval_script(path: Path):
|
|
12 |
stdout = None
|
13 |
stderr = None
|
14 |
exit_code = None
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
with open(path, 'r') as src, open(test_file, 'w') as dst:
|
21 |
-
dst.write(src.read())
|
22 |
-
|
23 |
-
# Initialize a Go module in the temporary directory
|
24 |
-
init_result = subprocess.run(
|
25 |
-
["go", "mod", "init", "testmodule"],
|
26 |
-
cwd=temp_dir,
|
27 |
-
capture_output=True,
|
28 |
-
text=True
|
29 |
-
)
|
30 |
-
|
31 |
-
if init_result.returncode != 0:
|
32 |
-
return {
|
33 |
-
"status": "SyntaxError",
|
34 |
-
"exit_code": init_result.returncode,
|
35 |
-
"stdout": init_result.stdout,
|
36 |
-
"stderr": init_result.stderr,
|
37 |
-
}
|
38 |
-
|
39 |
-
# Run the test
|
40 |
-
build = subprocess.run(
|
41 |
-
["go", "test", "-v"],
|
42 |
-
cwd=temp_dir,
|
43 |
-
timeout=30,
|
44 |
-
stdout=subprocess.PIPE,
|
45 |
-
stderr=subprocess.PIPE
|
46 |
-
)
|
47 |
|
48 |
stdout = build.stdout.decode("utf-8", errors="ignore")
|
49 |
stderr = build.stderr.decode("utf-8", errors="ignore")
|
50 |
exit_code = build.returncode
|
|
|
51 |
|
52 |
if "[setup failed]" in stdout or "[build failed]" in stdout:
|
53 |
status = "SyntaxError"
|
@@ -55,6 +27,8 @@ def eval_script(path: Path):
|
|
55 |
status = "Exception"
|
56 |
else:
|
57 |
status = "OK"
|
|
|
|
|
58 |
|
59 |
return {
|
60 |
"status": status,
|
|
|
2 |
from sys import exit
|
3 |
import subprocess
|
4 |
from pathlib import Path
|
|
|
|
|
5 |
from .generic_eval import main as gmain
|
6 |
|
7 |
|
|
|
10 |
stdout = None
|
11 |
stderr = None
|
12 |
exit_code = None
|
13 |
+
try:
|
14 |
+
build = subprocess.run(["go", "test", path],
|
15 |
+
timeout=30,
|
16 |
+
stdout=subprocess.PIPE,
|
17 |
+
stderr=subprocess.PIPE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
stdout = build.stdout.decode("utf-8", errors="ignore")
|
20 |
stderr = build.stderr.decode("utf-8", errors="ignore")
|
21 |
exit_code = build.returncode
|
22 |
+
# write to stderr just so that we can redirect stdout to a csv
|
23 |
|
24 |
if "[setup failed]" in stdout or "[build failed]" in stdout:
|
25 |
status = "SyntaxError"
|
|
|
27 |
status = "Exception"
|
28 |
else:
|
29 |
status = "OK"
|
30 |
+
except subprocess.TimeoutExpired:
|
31 |
+
status = "Timeout"
|
32 |
|
33 |
return {
|
34 |
"status": status,
|