Skip to content

Commit 3f75be4

Browse files
authored
Merge pull request #154 from afeld/autograder
set up basic autograder
2 parents d9fa721 + ed62c3b commit 3f75be4

File tree

12 files changed

+117
-36
lines changed

12 files changed

+117
-36
lines changed

.gitignore

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,6 @@ Untitled.ipynb
1515
# override the global
1616
!.vscode/settings.json
1717

18-
## Terraform ##
19-
20-
# Local .terraform directories
21-
**/.terraform/*
22-
23-
# .tfstate files
24-
*.tfstate
25-
*.tfstate.*
26-
27-
# Crash log files
28-
crash.log
29-
30-
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
31-
# password, private keys, and other secrets. These should not be part of version
32-
# control as they are data points which are potentially sensitive and subject
33-
# to change depending on the environment.
34-
#
35-
*.tfvars
36-
37-
# Ignore override files as they are usually used to override resources locally and so
38-
# are not checked in
39-
override.tf
40-
override.tf.json
41-
*_override.tf
42-
*_override.tf.json
43-
44-
# Include override files you do wish to add to version control using negated pattern
45-
#
46-
# !example_override.tf
47-
48-
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
49-
# example: *tfplan*
50-
51-
# Ignore CLI configuration files
52-
.terraformrc
53-
terraform.rc
18+
extras/autograder/results/
19+
extras/autograder/submission/
20+
autograder.zip

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ update_packages:
3030
./extras/scripts/update_lectures.sh
3131

3232
echo "Please update homework notebooks separately, in python-public-policy-assignments"
33+
34+
# based on https://gradescope-autograders.readthedocs.io/en/latest/manual_docker/
35+
autograde:
36+
mkdir -p ./extras/autograder/results ./extras/autograder/results
37+
38+
docker run --rm \
39+
-v ./extras/autograder:/autograder \
40+
gradescope/autograder-base \
41+
/bin/bash -c "/autograder/source/setup.sh && /autograder/source/run_autograder"
42+
43+
cat ./extras/autograder/results/results.json
44+
45+
build_autograder:
46+
# https://stackoverflow.com/a/17351814/358804
47+
git archive -o ./extras/autograder.zip HEAD:./extras/autograder/source
48+
49+
echo "Now upload extras/autograder.zip to Gradescope."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gradescope_utils
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
# based on
4+
# https://github.com/gradescope/autograder_samples/blob/master/python/src/run_autograder
5+
6+
set -ex
7+
8+
cd /autograder/source
9+
10+
python3 run_tests.py
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""based on https://github.com/gradescope/autograder_samples/blob/master/python/src/run_tests.py"""
2+
3+
import unittest
4+
from gradescope_utils.autograder_utils.json_test_runner import JSONTestRunner
5+
6+
if __name__ == '__main__':
7+
suite = unittest.defaultTestLoader.discover('tests')
8+
with open('/autograder/results/results.json', 'w') as f:
9+
JSONTestRunner(visibility='visible', stream=f).run(suite)

extras/autograder/source/setup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
apt-get install -y python3 python3-pip
6+
7+
pip3 install -r /autograder/source/requirements.txt
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""https://github.com/gradescope/gradescope-utils/tree/master/gradescope_utils/autograder_utils#readme"""
2+
3+
from unittest import TestCase
4+
import os
5+
from gradescope_utils.autograder_utils.decorators import number
6+
7+
8+
class TestFiles(TestCase):
9+
@number("1.1")
10+
def test_notebook_and_py_file(self):
11+
"""There should be exactly one notebook and one Python file submitted"""
12+
13+
files = os.listdir("/autograder/submission")
14+
extensions = [os.path.splitext(filename)[1] for filename in files]
15+
extensions.sort()
16+
self.assertListEqual(
17+
extensions, [".ipynb", ".py"], f"Files submitted: {', '.join(files)}"
18+
)

extras/environment.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ dependencies:
77
- black
88
- nbqa
99
- notebook=7.*
10+
- pip
11+
- pip:
12+
- gradescope_utils
1013

1114
# extensions
1215
- jupyter-resource-usage

extras/lib/school.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ class SchoolText:
148148
".zoom.us/rec",
149149
"- [google colab](https://colab.research.google.com/)",
150150
"anaconda",
151+
"autograder", # matches "grader"
151152
"built around it", # referring to Colab
152153
"columbia's graduate school of architecture", # bio
153154
"conda activate",
154155
"conda config",
155156
"create the environment",
156157
"dictreader",
157158
"for row in reader",
159+
"gradescope_utils", # matches "gradescope"
158160
"hannahkates/nyu-python-public-policy",
159161
"https://community.canvaslms.com/t5/canvas-basics-guide/what-are-grading-schemes/ta-p/41",
160162
"jupyterhub_url",

extras/terraform/.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Local .terraform directories
2+
**/.terraform/*
3+
4+
# .tfstate files
5+
*.tfstate
6+
*.tfstate.*
7+
8+
# Crash log files
9+
crash.log
10+
11+
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
12+
# password, private keys, and other secrets. These should not be part of version
13+
# control as they are data points which are potentially sensitive and subject
14+
# to change depending on the environment.
15+
#
16+
*.tfvars
17+
18+
# Ignore override files as they are usually used to override resources locally and so
19+
# are not checked in
20+
override.tf
21+
override.tf.json
22+
*_override.tf
23+
*_override.tf.json
24+
25+
# Include override files you do wish to add to version control using negated pattern
26+
#
27+
# !example_override.tf
28+
29+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
30+
# example: *tfplan*
31+
32+
# Ignore CLI configuration files
33+
.terraformrc
34+
terraform.rc

0 commit comments

Comments
 (0)