-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(run_submission): use a custom wrapper
This wrapper will only take effect if DEBUG is False and the sandboxing submodule isn't cloned.
- Loading branch information
1 parent
212b674
commit 8fa21a4
Showing
6 changed files
with
106 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""A sample wrapper script for running python submissions. | ||
The text in this file is read in :func:`run_submission` and | ||
executed if ``settings.USE_SANDBOXING`` is not ``True``. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import argparse | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
|
||
def parse_args() -> list[str]: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--write", action="append") | ||
parser.add_argument("--read", action="append") | ||
# since we're not being sandboxed, we don't need to do anything | ||
# with the grader arguments | ||
_grader_args, submission_args = parser.parse_known_args() | ||
|
||
if submission_args and submission_args[0] == "--": | ||
return submission_args[1:] | ||
return submission_args | ||
|
||
|
||
def find_python() -> str: | ||
venv = Path("{venv_path}") | ||
if venv.name == "None": | ||
return "{python}" | ||
if (python := venv / "bin" / "python").exists(): | ||
return str(python) | ||
return str(venv / "bin" / "python3") | ||
|
||
|
||
def main() -> int: | ||
args = parse_args() | ||
submission_path = Path("{submission_path}") | ||
|
||
if submission_path.suffix != ".py": | ||
raise NotImplementedError("Only python submissions are supported in DEBUG.") | ||
|
||
python = find_python() | ||
output = subprocess.run( | ||
[python, "--", str(submission_path), *args], | ||
stdout=sys.stdout, | ||
stderr=sys.stderr, | ||
check=False, | ||
) | ||
return output.returncode | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters