Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move docs from Django to website #72

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
70 changes: 32 additions & 38 deletions docs/source/usage/graders/examples/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import subprocess
import sys
import tempfile
from pathlib import Path

submission = sys.argv[1]
Expand All @@ -11,41 +12,34 @@
# make sure to use the absolute path
INPUT_FILE = (Path(__file__).parent / "input.txt").resolve()

# output file is in the same directory as the student submission
# This way we can avoid multiple submissions trying to write to
# the same file.
# Again, making sure to use the absolute path
OUTPUT_FILE = (student_submission.parent / "output.txt").resolve()


command = [
sys.executable,
submission,
# give read permissions to the input
# making sure to use the absolute path to the file
"--read",
INPUT_FILE,
# and allow them to read/write to the output file
"--write",
OUTPUT_FILE,
# and then pass the arguments to the student submission
"--",
INPUT_FILE,
OUTPUT_FILE,
]

resp = subprocess.run(
command,
stdout=sys.stdout,
stderr=subprocess.STDOUT,
check=False,
)

if (
resp.returncode != 0
or not OUTPUT_FILE.exists()
or OUTPUT_FILE.read_text() != INPUT_FILE.read_text()
):
print("Score: 0%")
else:
print("Score: 100%")
# note that since multiple submissions may be running at the same time
# we should make sure to use a filename that's not already in use
# to prevent different submissions from trying to access the same file.
with tempfile.NamedTemporaryFile(dir=student_submission.parent) as f:
command = [
sys.executable,
submission,
# give read permissions to the input
# making sure to use the absolute path to the file
"--read",
INPUT_FILE,
# and allow them to read/write to the output file
"--write",
f.name,
# and then pass the arguments to the student submission
"--",
INPUT_FILE,
f.name,
]

resp = subprocess.run(
command,
stdout=sys.stdout,
stderr=subprocess.STDOUT,
check=False,
)

if resp.returncode != 0 or Path(f.name).read_text() != INPUT_FILE.read_text():
print("Score: 0%")
else:
print("Score: 100%")
1 change: 0 additions & 1 deletion tin/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
{% endif %}
{% endif %}
<li><i class="fa fa-chevron-right"></i></li>
JasonGrace2282 marked this conversation as resolved.
Show resolved Hide resolved
<li><a href="https://tjcsl.github.io/tin/">Docs</a></li>
{% if venvs_app %}
<li><i class="fa fa-chevron-right"></i></li>
<li><a href="{% url 'venvs:index' %}">Virtual Environments</a></li>
Expand Down
Loading