dlai-grader 1.20.0__tar.gz → 1.21.1__tar.gz

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.

Files changed (22) hide show
  1. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/PKG-INFO +1 -1
  2. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/__init__.py +1 -1
  3. dlai_grader-1.21.1/dlai_grader/compiler.py +75 -0
  4. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/templates.py +4 -5
  5. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader.egg-info/PKG-INFO +1 -1
  6. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/setup.py +1 -1
  7. dlai_grader-1.20.0/dlai_grader/compiler.py +0 -37
  8. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/LICENSE +0 -0
  9. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/README.md +0 -0
  10. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/cli.py +0 -0
  11. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/config.py +0 -0
  12. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/grading.py +0 -0
  13. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/io.py +0 -0
  14. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/notebook.py +0 -0
  15. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/py.typed +0 -0
  16. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader/types.py +0 -0
  17. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader.egg-info/SOURCES.txt +0 -0
  18. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader.egg-info/dependency_links.txt +0 -0
  19. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader.egg-info/entry_points.txt +0 -0
  20. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader.egg-info/requires.txt +0 -0
  21. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/dlai_grader.egg-info/top_level.txt +0 -0
  22. {dlai_grader-1.20.0 → dlai_grader-1.21.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dlai-grader
3
- Version: 1.20.0
3
+ Version: 1.21.1
4
4
  Summary: Grading utilities for DLAI courses
5
5
  Home-page: https://github.com/https-deeplearning-ai/grader
6
6
  Author: Andres Zarta
@@ -6,6 +6,6 @@ from . import grading
6
6
  from . import types
7
7
 
8
8
 
9
- __version__ = "1.20.0"
9
+ __version__ = "1.21.1"
10
10
  __author__ = "Andres Zarta"
11
11
  __credits__ = "DeepLearning.AI"
@@ -0,0 +1,75 @@
1
+ import ast
2
+ from types import ModuleType
3
+ from contextlib import nullcontext
4
+ from nbformat.notebooknode import NotebookNode
5
+ from .io import suppress_stdout_stderr
6
+
7
+
8
+ def compile_module(
9
+ code_as_str: str,
10
+ module_name: str,
11
+ wipe_global_state: bool = False,
12
+ verbose: bool = True,
13
+ ) -> ModuleType:
14
+ """Compiles the string representation of some code and returns a compiled module.
15
+ Args:
16
+ code_as_str (str): Code represented as string.
17
+ module_name (str): Name of the module.
18
+ wipe_global_state (bool): If true then no global state is compiled. Defaults to False.
19
+ verbose (bool): Whether to print out streams as a result of compilation. Defaults to True.
20
+ Returns:
21
+ ModuleType: The actual module that can be used to call functions/variables/etc.
22
+ """
23
+ code_ast = ast.parse(code_as_str)
24
+
25
+ if wipe_global_state:
26
+ for node in code_ast.body[:]:
27
+ if not isinstance(
28
+ node, (ast.FunctionDef, ast.Import, ast.ImportFrom, ast.ClassDef)
29
+ ):
30
+ code_ast.body.remove(node)
31
+
32
+ with nullcontext() if verbose else suppress_stdout_stderr():
33
+ module = ModuleType(module_name)
34
+ code = compile(code_ast, f"{module_name}.py", "exec")
35
+ exec(code, module.__dict__)
36
+ return module
37
+
38
+
39
+ def compile_partial_module(
40
+ notebook: NotebookNode,
41
+ module_name: str,
42
+ verbose: bool = True,
43
+ exit_on_error: bool = False,
44
+ ) -> ModuleType:
45
+ """Iterates over the code cells of a notebook and includes the ones that run to the compiled module.
46
+ Args:
47
+ notebook (NotebookNode): Notebook from learner.
48
+ module_name (str): Name of the module.
49
+ verbose (bool): Whether to print out streams as a result of compilation. Defaults to True.
50
+ Returns:
51
+ ModuleType: The actual module that can be used to call functions/variables/etc.
52
+ """
53
+ code_cells = [cell.source for cell in notebook.cells if cell.cell_type == "code"]
54
+ module = ModuleType(module_name)
55
+
56
+ for i, cell_code in enumerate(code_cells):
57
+ try:
58
+ compiled_code = compile(cell_code, f"<cell {i}>", "exec")
59
+
60
+ with nullcontext() if verbose else suppress_stdout_stderr():
61
+ exec(compiled_code, module.__dict__)
62
+
63
+ except Exception as e:
64
+ if exit_on_error:
65
+ print(
66
+ f"Error during execution of cell. Aborting full compilation.\n\nContents:\n\n{cell_code}\n\nException:\n\n{e}\n"
67
+ )
68
+ break
69
+
70
+ print(
71
+ f"Error during execution of cell but kept going.\n\nContents:\n\n{cell_code}\n\nException:\n\n{e}\n"
72
+ )
73
+ continue
74
+
75
+ return module
@@ -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 compile_module
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 = compile_module(script, "learner_mod", verbose=False)
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"Unable to find object required for grading in your code.\\n{additional_msg}",
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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dlai-grader
3
- Version: 1.20.0
3
+ Version: 1.21.1
4
4
  Summary: Grading utilities for DLAI courses
5
5
  Home-page: https://github.com/https-deeplearning-ai/grader
6
6
  Author: Andres Zarta
@@ -5,7 +5,7 @@ with open("README.md", "r") as f:
5
5
 
6
6
  setup(
7
7
  name="dlai-grader",
8
- version="1.20.0",
8
+ version="1.21.1",
9
9
  description="Grading utilities for DLAI courses",
10
10
  url="https://github.com/https-deeplearning-ai/grader",
11
11
  author="Andres Zarta",
@@ -1,37 +0,0 @@
1
- import ast
2
- import sys
3
- from types import ModuleType
4
- from contextlib import nullcontext
5
- from .io import suppress_stdout_stderr
6
-
7
-
8
- def compile_module(
9
- code_as_str: str,
10
- module_name: str,
11
- wipe_global_state: bool = False,
12
- verbose: bool = True,
13
- ) -> ModuleType:
14
- """Compiles the string representation of some code and returns a compiled module.
15
- Args:
16
- code_as_str (str): Code represented as string.
17
- module_name (str): Name of the module.
18
- wipe_global_state (bool): If true then no global state is compiled. Defaults to False.
19
- verbose (bool): Whether to print out streams as a result of compilation. Defaults to True.
20
- Returns:
21
- ModuleType: The actual module that can be used to call functions/variables/etc.
22
- """
23
- code_ast = ast.parse(code_as_str)
24
-
25
- if wipe_global_state:
26
- for node in code_ast.body[:]:
27
- if not isinstance(
28
- node, (ast.FunctionDef, ast.Import, ast.ImportFrom, ast.ClassDef)
29
- ):
30
- code_ast.body.remove(node)
31
-
32
- with nullcontext() if verbose else suppress_stdout_stderr():
33
- module = ModuleType(module_name)
34
- code = compile(code_ast, f"{module_name}.py", "exec")
35
- sys.modules[module_name] = module
36
- exec(code, module.__dict__)
37
- return module
File without changes
File without changes
File without changes