dlai-grader 1.20.0__py3-none-any.whl → 1.21.0__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.
- dlai_grader/__init__.py +1 -1
- dlai_grader/compiler.py +34 -2
- dlai_grader/templates.py +4 -5
- {dlai_grader-1.20.0.dist-info → dlai_grader-1.21.0.dist-info}/METADATA +1 -1
- {dlai_grader-1.20.0.dist-info → dlai_grader-1.21.0.dist-info}/RECORD +9 -9
- {dlai_grader-1.20.0.dist-info → dlai_grader-1.21.0.dist-info}/LICENSE +0 -0
- {dlai_grader-1.20.0.dist-info → dlai_grader-1.21.0.dist-info}/WHEEL +0 -0
- {dlai_grader-1.20.0.dist-info → dlai_grader-1.21.0.dist-info}/entry_points.txt +0 -0
- {dlai_grader-1.20.0.dist-info → dlai_grader-1.21.0.dist-info}/top_level.txt +0 -0
dlai_grader/__init__.py
CHANGED
dlai_grader/compiler.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import ast
|
|
2
|
-
import sys
|
|
3
2
|
from types import ModuleType
|
|
4
3
|
from contextlib import nullcontext
|
|
4
|
+
from nbformat.notebooknode import NotebookNode
|
|
5
5
|
from .io import suppress_stdout_stderr
|
|
6
6
|
|
|
7
7
|
|
|
@@ -32,6 +32,38 @@ def compile_module(
|
|
|
32
32
|
with nullcontext() if verbose else suppress_stdout_stderr():
|
|
33
33
|
module = ModuleType(module_name)
|
|
34
34
|
code = compile(code_ast, f"{module_name}.py", "exec")
|
|
35
|
-
sys.modules[module_name] = module
|
|
36
35
|
exec(code, module.__dict__)
|
|
37
36
|
return module
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def compile_partial_module(
|
|
40
|
+
notebook: NotebookNode,
|
|
41
|
+
module_name: str,
|
|
42
|
+
verbose: bool = True,
|
|
43
|
+
) -> ModuleType:
|
|
44
|
+
"""Iterates over the code cells of a notebook and includes the ones that run to the compiled module.
|
|
45
|
+
Args:
|
|
46
|
+
notebook (NotebookNode): Notebook from learner.
|
|
47
|
+
module_name (str): Name of the module.
|
|
48
|
+
verbose (bool): Whether to print out streams as a result of compilation. Defaults to True.
|
|
49
|
+
Returns:
|
|
50
|
+
ModuleType: The actual module that can be used to call functions/variables/etc.
|
|
51
|
+
"""
|
|
52
|
+
code_cells = [cell.source for cell in notebook.cells if cell.cell_type == "code"]
|
|
53
|
+
module = ModuleType(module_name)
|
|
54
|
+
|
|
55
|
+
for i, cell_code in enumerate(code_cells):
|
|
56
|
+
try:
|
|
57
|
+
compiled_code = compile(cell_code, f"<cell {i}>", "exec")
|
|
58
|
+
|
|
59
|
+
with nullcontext() if verbose else suppress_stdout_stderr():
|
|
60
|
+
exec(compiled_code, module.__dict__)
|
|
61
|
+
|
|
62
|
+
except Exception as e:
|
|
63
|
+
if verbose:
|
|
64
|
+
print(
|
|
65
|
+
f"Error during execution of cell. Aborting full compilation.\n\nContents:\n\n{cell_code}\n\nException:\n\n{e}\n"
|
|
66
|
+
)
|
|
67
|
+
break
|
|
68
|
+
|
|
69
|
+
return module
|
dlai_grader/templates.py
CHANGED
|
@@ -165,7 +165,7 @@ def load_templates() -> Dict[str, str]:
|
|
|
165
165
|
|
|
166
166
|
entry_py = """
|
|
167
167
|
from dlai_grader.config import Config
|
|
168
|
-
from dlai_grader.compiler import
|
|
168
|
+
from dlai_grader.compiler import compile_partial_module
|
|
169
169
|
from dlai_grader.io import read_notebook, copy_submission_to_workdir, send_feedback
|
|
170
170
|
|
|
171
171
|
from dlai_grader.notebook import (
|
|
@@ -204,14 +204,13 @@ def load_templates() -> Dict[str, str]:
|
|
|
204
204
|
for t in transformations:
|
|
205
205
|
nb = t(nb)
|
|
206
206
|
|
|
207
|
-
script = notebook_to_script(nb)
|
|
208
|
-
|
|
209
207
|
try:
|
|
210
|
-
learner_mod =
|
|
208
|
+
learner_mod = compile_partial_module(nb, "learner_mod", verbose=False)
|
|
211
209
|
except Exception as e:
|
|
212
210
|
send_feedback(
|
|
213
211
|
0.0,
|
|
214
212
|
f"There was a problem compiling the code from your notebook, please check that you saved before submitting. Details:\\n{str(e)}",
|
|
213
|
+
err=True,
|
|
215
214
|
)
|
|
216
215
|
|
|
217
216
|
solution_nb = read_notebook(c.solution_file_path)
|
|
@@ -240,7 +239,7 @@ def load_templates() -> Dict[str, str]:
|
|
|
240
239
|
|
|
241
240
|
send_feedback(
|
|
242
241
|
0.0,
|
|
243
|
-
f"
|
|
242
|
+
f"Object required for grading not found. If you haven't completed the exercise this is expected. Otherwise, check your solution as grader omits cells that throw errors.\n{additional_msg}",
|
|
244
243
|
err=True,
|
|
245
244
|
)
|
|
246
245
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
dlai_grader/__init__.py,sha256=
|
|
1
|
+
dlai_grader/__init__.py,sha256=YwnDeHfbUUK5KqiAGzDNf_Zm3CvLxy12XuzAL1hyrrA,211
|
|
2
2
|
dlai_grader/cli.py,sha256=NIwboE-AFn1LXOFmF4O70Ow0fkRxgclG_eMwmWiua38,4917
|
|
3
|
-
dlai_grader/compiler.py,sha256=
|
|
3
|
+
dlai_grader/compiler.py,sha256=VuFWHXWlOLYuZgNHOm19Ef7hbWQX7kdAwk8auBAxsYs,2506
|
|
4
4
|
dlai_grader/config.py,sha256=HQ3dzaFpRswIA_7EC8XdP8DdJH-XePsbMQMHG8Esblc,1638
|
|
5
5
|
dlai_grader/grading.py,sha256=Gmft9b7M8At_y_WZDatYdW6tinZMfqQoT7bDXp6uz2I,4606
|
|
6
6
|
dlai_grader/io.py,sha256=TB9d01AK5FIbFUQwM8AqOOfuMWzjzrit98i3MhK5AqU,8234
|
|
7
7
|
dlai_grader/notebook.py,sha256=noMU6DzPVylSjkHmSBUcmquVvAz4JigbRtbQrVYJdic,11830
|
|
8
8
|
dlai_grader/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
-
dlai_grader/templates.py,sha256=
|
|
9
|
+
dlai_grader/templates.py,sha256=zDLueSS6E6RbCY36sMyQFZ0RedBfsImi9ybBIk6JtBg,7903
|
|
10
10
|
dlai_grader/types.py,sha256=_IIVbYL9cMmwA6in0aI5fEWCIaAMNcQbxG64X1P1CkE,335
|
|
11
|
-
dlai_grader-1.
|
|
12
|
-
dlai_grader-1.
|
|
13
|
-
dlai_grader-1.
|
|
14
|
-
dlai_grader-1.
|
|
15
|
-
dlai_grader-1.
|
|
16
|
-
dlai_grader-1.
|
|
11
|
+
dlai_grader-1.21.0.dist-info/LICENSE,sha256=a_kch_UqdJPtyxk35QJr9O84K_koPixqWPYW9On4-io,1072
|
|
12
|
+
dlai_grader-1.21.0.dist-info/METADATA,sha256=vvZKID0w9qu46d0tPqwsjek-YP480jiKrYcbVOoGuII,8618
|
|
13
|
+
dlai_grader-1.21.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
|
14
|
+
dlai_grader-1.21.0.dist-info/entry_points.txt,sha256=4OcSAUIluONXa3ymViQ7CBQ2Lk52nb6xZnfph1rlMnk,71
|
|
15
|
+
dlai_grader-1.21.0.dist-info/top_level.txt,sha256=4YKtA3ztisFtx_g4hsGivy3J2NHnXxFziIMqawC8HWg,12
|
|
16
|
+
dlai_grader-1.21.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|