dlai-grader 1.22.2__py3-none-any.whl → 2.0b2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dlai-grader might be problematic. Click here for more details.

@@ -0,0 +1,71 @@
1
+ import traceback
2
+ from dlai_grader.config import Config, get_part_id
3
+ from dlai_grader.compiler import compile_partial_module
4
+ from dlai_grader.io import read_notebook, copy_submission_to_workdir, send_feedback
5
+ from dlai_grader.notebook import keep_tagged_cells
6
+ from dlai_grader.grading import compute_grading_score, graded_obj_missing
7
+ from grader import handle_part_id
8
+
9
+
10
+ def notebook_grading(config, compile_solution=False):
11
+ try:
12
+ nb = read_notebook(config.submission_file_path)
13
+ except Exception as e:
14
+ msg = f"There was a problem reading your notebook. Details:\n{e!s}"
15
+ send_feedback(0.0, msg, err=True)
16
+
17
+ transformations = [keep_tagged_cells()]
18
+ for t in transformations:
19
+ nb = t(nb)
20
+
21
+ try:
22
+ learner_mod = compile_partial_module(nb, "learner_mod", verbose=False)
23
+ except Exception as e:
24
+ msg = f"There was a problem compiling the code from your notebook, please check that you saved before submitting. Details:\n{e!s}"
25
+ send_feedback(0.0, msg, err=True)
26
+
27
+ solution_mod = None
28
+ if compile_solution:
29
+ solution_nb = read_notebook(config.solution_file_path)
30
+ for t in transformations:
31
+ solution_nb = t(solution_nb)
32
+ solution_mod = compile_partial_module(
33
+ solution_nb,
34
+ "solution_mod",
35
+ verbose=False,
36
+ )
37
+
38
+ return learner_mod, solution_mod
39
+
40
+
41
+ def main() -> None:
42
+ copy_submission_to_workdir()
43
+
44
+ part_id = get_part_id()
45
+
46
+ c = Config()
47
+
48
+ learner_mod, _ = notebook_grading(c)
49
+
50
+ g_func = handle_part_id(part_id)(learner_mod)
51
+
52
+ try:
53
+ cases = g_func()
54
+ except Exception as e:
55
+ msg = f"There was an error grading your submission. Details:\n{e!s}"
56
+ send_feedback(0.0, msg, err=True)
57
+
58
+ if graded_obj_missing(cases):
59
+ msg = "Object required for grading not found. If you haven't completed the exercise this might be expected. Otherwise, check your solution as grader omits cells that throw errors."
60
+ send_feedback(0.0, msg, err=True)
61
+
62
+ score, feedback = compute_grading_score(cases)
63
+ send_feedback(score, feedback)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ try:
68
+ main()
69
+ except Exception as e:
70
+ msg = f"There was an error with the program. Exception:\n{e!s}.\nTraceback:\n{traceback.format_exc()}"
71
+ send_feedback(0.0, msg, err=True)
@@ -0,0 +1,90 @@
1
+ import traceback
2
+ from dlai_grader.config import Config, get_part_id
3
+ from dlai_grader.compiler import compile_partial_module
4
+ from dlai_grader.io import read_notebook, copy_submission_to_workdir, send_feedback
5
+ from dlai_grader.notebook import keep_tagged_cells
6
+ from dlai_grader.grading import (
7
+ compute_grading_score,
8
+ graded_obj_missing,
9
+ LearnerSubmission,
10
+ )
11
+ from grader import handle_part_id
12
+
13
+
14
+ def notebook_grading(config, compile_solution=False):
15
+ try:
16
+ nb = read_notebook(config.submission_file_path)
17
+ except Exception as e:
18
+ msg = f"There was a problem reading your notebook. Details:\n{e!s}"
19
+ send_feedback(0.0, msg, err=True)
20
+
21
+ transformations = [keep_tagged_cells()]
22
+ for t in transformations:
23
+ nb = t(nb)
24
+
25
+ try:
26
+ learner_mod = compile_partial_module(nb, "learner_mod", verbose=False)
27
+ except Exception as e:
28
+ msg = f"There was a problem compiling the code from your notebook, please check that you saved before submitting. Details:\n{e!s}"
29
+ send_feedback(0.0, msg, err=True)
30
+
31
+ solution_mod = None
32
+ if compile_solution:
33
+ solution_nb = read_notebook(config.solution_file_path)
34
+ for t in transformations:
35
+ solution_nb = t(solution_nb)
36
+ solution_mod = compile_partial_module(
37
+ solution_nb,
38
+ "solution_mod",
39
+ verbose=False,
40
+ )
41
+
42
+ return learner_mod, solution_mod
43
+
44
+
45
+ def non_notebook_grading(config):
46
+ try:
47
+ with open(config.submission_file_path, "r") as file:
48
+ contents = file.read()
49
+ except Exception as e:
50
+ msg = f"There was an error reading your submission. Details:\n{e!s}"
51
+ send_feedback(0.0, msg, err=True)
52
+
53
+ return LearnerSubmission(submission=contents)
54
+
55
+
56
+ def main() -> None:
57
+ part_id = get_part_id()
58
+
59
+ match part_id:
60
+ case "123":
61
+ copy_submission_to_workdir(file_name="{{EXTRA_FILE_NAME}}")
62
+ c = Config(submission_file="{{EXTRA_FILE_NAME}}")
63
+ learner_mod = non_notebook_grading(c)
64
+ case _:
65
+ copy_submission_to_workdir()
66
+ c = Config()
67
+ learner_mod, _ = notebook_grading(c)
68
+
69
+ g_func = handle_part_id(part_id)(learner_mod)
70
+
71
+ try:
72
+ cases = g_func()
73
+ except Exception as e:
74
+ msg = f"There was an error grading your submission. Details:\n{e!s}"
75
+ send_feedback(0.0, msg, err=True)
76
+
77
+ if graded_obj_missing(cases):
78
+ msg = "Object required for grading not found. If you haven't completed the exercise this might be expected. Otherwise, check your solution as grader omits cells that throw errors."
79
+ send_feedback(0.0, msg, err=True)
80
+
81
+ score, feedback = compute_grading_score(cases)
82
+ send_feedback(score, feedback)
83
+
84
+
85
+ if __name__ == "__main__":
86
+ try:
87
+ main()
88
+ except Exception as e:
89
+ msg = f"There was an error with the program. Exception:\n{e!s}.\nTraceback:\n{traceback.format_exc()}"
90
+ send_feedback(0.0, msg, err=True)
@@ -0,0 +1,71 @@
1
+ import traceback
2
+ from dlai_grader.config import Config, get_part_id
3
+ from dlai_grader.compiler import compile_partial_module
4
+ from dlai_grader.io import read_notebook, copy_submission_to_workdir, send_feedback
5
+ from dlai_grader.notebook import keep_tagged_cells
6
+ from dlai_grader.grading import compute_grading_score, graded_obj_missing
7
+ from grader import handle_part_id
8
+
9
+
10
+ def notebook_grading(config, compile_solution=False):
11
+ try:
12
+ nb = read_notebook(config.submission_file_path)
13
+ except Exception as e:
14
+ msg = f"There was a problem reading your notebook. Details:\n{e!s}"
15
+ send_feedback(0.0, msg, err=True)
16
+
17
+ transformations = [keep_tagged_cells()]
18
+ for t in transformations:
19
+ nb = t(nb)
20
+
21
+ try:
22
+ learner_mod = compile_partial_module(nb, "learner_mod", verbose=False)
23
+ except Exception as e:
24
+ msg = f"There was a problem compiling the code from your notebook, please check that you saved before submitting. Details:\n{e!s}"
25
+ send_feedback(0.0, msg, err=True)
26
+
27
+ solution_mod = None
28
+ if compile_solution:
29
+ solution_nb = read_notebook(config.solution_file_path)
30
+ for t in transformations:
31
+ solution_nb = t(solution_nb)
32
+ solution_mod = compile_partial_module(
33
+ solution_nb,
34
+ "solution_mod",
35
+ verbose=False,
36
+ )
37
+
38
+ return learner_mod, solution_mod
39
+
40
+
41
+ def main() -> None:
42
+ copy_submission_to_workdir()
43
+
44
+ part_id = get_part_id()
45
+
46
+ c = Config()
47
+
48
+ learner_mod, solution_mod = notebook_grading(c, compile_solution=True)
49
+
50
+ g_func = handle_part_id(part_id)(learner_mod, solution_mod)
51
+
52
+ try:
53
+ cases = g_func()
54
+ except Exception as e:
55
+ msg = f"There was an error grading your submission. Details:\n{e!s}"
56
+ send_feedback(0.0, msg, err=True)
57
+
58
+ if graded_obj_missing(cases):
59
+ msg = "Object required for grading not found. If you haven't completed the exercise this might be expected. Otherwise, check your solution as grader omits cells that throw errors."
60
+ send_feedback(0.0, msg, err=True)
61
+
62
+ score, feedback = compute_grading_score(cases)
63
+ send_feedback(score, feedback)
64
+
65
+
66
+ if __name__ == "__main__":
67
+ try:
68
+ main()
69
+ except Exception as e:
70
+ msg = f"There was an error with the program. Exception:\n{e!s}.\nTraceback:\n{traceback.format_exc()}"
71
+ send_feedback(0.0, msg, err=True)
@@ -0,0 +1,90 @@
1
+ import traceback
2
+ from dlai_grader.config import Config, get_part_id
3
+ from dlai_grader.compiler import compile_partial_module
4
+ from dlai_grader.io import read_notebook, copy_submission_to_workdir, send_feedback
5
+ from dlai_grader.notebook import keep_tagged_cells
6
+ from dlai_grader.grading import (
7
+ compute_grading_score,
8
+ graded_obj_missing,
9
+ LearnerSubmission,
10
+ )
11
+ from grader import handle_part_id
12
+
13
+
14
+ def notebook_grading(config, compile_solution=False):
15
+ try:
16
+ nb = read_notebook(config.submission_file_path)
17
+ except Exception as e:
18
+ msg = f"There was a problem reading your notebook. Details:\n{e!s}"
19
+ send_feedback(0.0, msg, err=True)
20
+
21
+ transformations = [keep_tagged_cells()]
22
+ for t in transformations:
23
+ nb = t(nb)
24
+
25
+ try:
26
+ learner_mod = compile_partial_module(nb, "learner_mod", verbose=False)
27
+ except Exception as e:
28
+ msg = f"There was a problem compiling the code from your notebook, please check that you saved before submitting. Details:\n{e!s}"
29
+ send_feedback(0.0, msg, err=True)
30
+
31
+ solution_mod = None
32
+ if compile_solution:
33
+ solution_nb = read_notebook(config.solution_file_path)
34
+ for t in transformations:
35
+ solution_nb = t(solution_nb)
36
+ solution_mod = compile_partial_module(
37
+ solution_nb,
38
+ "solution_mod",
39
+ verbose=False,
40
+ )
41
+
42
+ return learner_mod, solution_mod
43
+
44
+
45
+ def non_notebook_grading(config):
46
+ try:
47
+ with open(config.submission_file_path, "r") as file:
48
+ contents = file.read()
49
+ except Exception as e:
50
+ msg = f"There was an error reading your submission. Details:\n{e!s}"
51
+ send_feedback(0.0, msg, err=True)
52
+
53
+ return LearnerSubmission(submission=contents)
54
+
55
+
56
+ def main() -> None:
57
+ part_id = get_part_id()
58
+
59
+ match part_id:
60
+ case "123":
61
+ copy_submission_to_workdir(file_name="{{EXTRA_FILE_NAME}}")
62
+ c = Config(submission_file="{{EXTRA_FILE_NAME}}")
63
+ learner_mod = non_notebook_grading(c)
64
+ case _:
65
+ copy_submission_to_workdir()
66
+ c = Config()
67
+ learner_mod, solution_mod = notebook_grading(c, compile_solution=True)
68
+
69
+ g_func = handle_part_id(part_id)(learner_mod, solution_mod)
70
+
71
+ try:
72
+ cases = g_func()
73
+ except Exception as e:
74
+ msg = f"There was an error grading your submission. Details:\n{e!s}"
75
+ send_feedback(0.0, msg, err=True)
76
+
77
+ if graded_obj_missing(cases):
78
+ msg = "Object required for grading not found. If you haven't completed the exercise this might be expected. Otherwise, check your solution as grader omits cells that throw errors."
79
+ send_feedback(0.0, msg, err=True)
80
+
81
+ score, feedback = compute_grading_score(cases)
82
+ send_feedback(score, feedback)
83
+
84
+
85
+ if __name__ == "__main__":
86
+ try:
87
+ main()
88
+ except Exception as e:
89
+ msg = f"There was an error with the program. Exception:\n{e!s}.\nTraceback:\n{traceback.format_exc()}"
90
+ send_feedback(0.0, msg, err=True)
@@ -0,0 +1,32 @@
1
+ from types import ModuleType, FunctionType
2
+ from dlai_grader.grading import test_case, object_to_grade
3
+ from dlai_grader.types import grading_function, grading_wrapper, learner_submission
4
+
5
+
6
+ def part_1(
7
+ learner_mod: learner_submission,
8
+ solution_mod: ModuleType | None = None,
9
+ ) -> grading_function:
10
+ @object_to_grade(learner_mod, "learner_func")
11
+ def g(learner_func: FunctionType) -> list[test_case]:
12
+
13
+ cases: list[test_case] = []
14
+
15
+ t = test_case()
16
+ if not isinstance(learner_func, FunctionType):
17
+ t.fail()
18
+ t.msg = "learner_func has incorrect type"
19
+ t.want = FunctionType
20
+ t.got = type(learner_func)
21
+ return [t]
22
+
23
+ return cases
24
+
25
+ return g
26
+
27
+
28
+ def handle_part_id(part_id: str) -> grading_wrapper:
29
+ grader_dict: dict[str, grading_wrapper] = {
30
+ "": part_1,
31
+ }
32
+ return grader_dict[part_id]