Spaces:
Runtime error
Runtime error
Muennighoff
commited on
Commit
•
f877f8e
1
Parent(s):
9c695f9
Add rust
Browse files- execute.py +23 -0
execute.py
CHANGED
@@ -48,6 +48,8 @@ def check_correctness(check_program, timeout, task_id, completion_id, language):
|
|
48 |
p = multiprocessing.Process(target=unsafe_execute_java, args=(check_program, result, timeout))
|
49 |
elif language == "javascript":
|
50 |
p = multiprocessing.Process(target=unsafe_execute_js, args=(check_program, result, timeout))
|
|
|
|
|
51 |
else:
|
52 |
raise ValueError(f"Language {language} not supported. Feel free to add it :)")
|
53 |
|
@@ -220,6 +222,27 @@ def unsafe_execute_js(check_program, result, timeout):
|
|
220 |
except subprocess.TimeoutExpired as e:
|
221 |
result.append("timed out")
|
222 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
@contextlib.contextmanager
|
225 |
def time_limit(seconds):
|
|
|
48 |
p = multiprocessing.Process(target=unsafe_execute_java, args=(check_program, result, timeout))
|
49 |
elif language == "javascript":
|
50 |
p = multiprocessing.Process(target=unsafe_execute_js, args=(check_program, result, timeout))
|
51 |
+
elif language == "rust":
|
52 |
+
p = multiprocessing.Process(target=unsafe_execute_rust, args=(check_program, result, timeout))
|
53 |
else:
|
54 |
raise ValueError(f"Language {language} not supported. Feel free to add it :)")
|
55 |
|
|
|
222 |
except subprocess.TimeoutExpired as e:
|
223 |
result.append("timed out")
|
224 |
|
225 |
+
def unsafe_execute_rust(check_program, result, timeout):
|
226 |
+
|
227 |
+
with create_tempdir():
|
228 |
+
open(f"test.rs", 'w').write(check_program)
|
229 |
+
|
230 |
+
log_path = "test.jsonl"
|
231 |
+
cargo_check: str = "cargo check --bin test --message-format json >> " + log_path
|
232 |
+
returned_val_compilation = os.system(cargo_check)
|
233 |
+
if returned_val_compilation == 0:
|
234 |
+
|
235 |
+
cargo_test: str = "cargo test --bin test --message-format json >> " + log_path
|
236 |
+
returned_val_execution = os.system(cargo_test)
|
237 |
+
|
238 |
+
if returned_val_execution == 0:
|
239 |
+
result.append("passed")
|
240 |
+
else:
|
241 |
+
result.append("failed: execution error")
|
242 |
+
else:
|
243 |
+
result.append("failed: compilation error")
|
244 |
+
|
245 |
+
|
246 |
|
247 |
@contextlib.contextmanager
|
248 |
def time_limit(seconds):
|