Skip to content

Commit

Permalink
Un-reverse DeduplicateIds order
Browse files Browse the repository at this point in the history
  • Loading branch information
tuncbkose authored and Gehock committed Oct 1, 2024
1 parent c544f16 commit 05ca3f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
35 changes: 21 additions & 14 deletions nbgrader/converters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,25 +387,32 @@ def _handle_failure(gd: typing.Dict[str, str]) -> None:

# convert all the notebooks
for notebook_filename in self.notebooks:
self.convert_single_notebook(notebook_filename)
try:
self.convert_single_notebook(notebook_filename)

# Exceptions that shouldn't interrupt the entire conversion process should go here
# Those that should go in outer try/except
except UnresponsiveKernelError:
self.log.error(
"While processing assignment %s, the kernel became "
"unresponsive and we could not interrupt it. This probably "
"means that the students' code has an infinite loop that "
"consumes a lot of memory or something similar. nbgrader "
"doesn't know how to deal with this problem, so you will "
"have to manually edit the students' code (for example, to "
"just throw an error rather than enter an infinite loop). ",
assignment)
errors.append((gd['assignment_id'], gd['student_id']))
_handle_failure(gd)

except Exception as e:
raise e

# set assignment permissions
self.set_permissions(gd['assignment_id'], gd['student_id'])
self.run_post_convert_hook()

except UnresponsiveKernelError:
self.log.error(
"While processing assignment %s, the kernel became "
"unresponsive and we could not interrupt it. This probably "
"means that the students' code has an infinite loop that "
"consumes a lot of memory or something similar. nbgrader "
"doesn't know how to deal with this problem, so you will "
"have to manually edit the students' code (for example, to "
"just throw an error rather than enter an infinite loop). ",
assignment)
errors.append((gd['assignment_id'], gd['student_id']))
_handle_failure(gd)

# Exceptions that should interrupt the entire conversion go here
except sqlalchemy.exc.OperationalError:
_handle_failure(gd)
self.log.error(traceback.format_exc())
Expand Down
6 changes: 0 additions & 6 deletions nbgrader/preprocessors/deduplicateids.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ def preprocess(self, nb: NotebookNode, resources: ResourcesDict) -> Tuple[Notebo
# keep track of grade ids encountered so far
self.grade_ids = set([])

# reverse cell order
nb.cells = nb.cells[::-1]

# process each cell in reverse order
nb, resources = super(DeduplicateIds, self).preprocess(nb, resources)

# unreverse cell order
nb.cells = nb.cells[::-1]

return nb, resources

def preprocess_cell(self,
Expand Down
12 changes: 6 additions & 6 deletions nbgrader/tests/preprocessors/test_deduplicateids.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def test_duplicate_grade_cell(self, preprocessor):

nb, resources = preprocessor.preprocess(nb, {})

assert nb.cells[0].metadata.nbgrader == {}
assert nb.cells[1].metadata.nbgrader != {}
assert nb.cells[0].metadata.nbgrader != {}
assert nb.cells[1].metadata.nbgrader == {}

def test_duplicate_solution_cell(self, preprocessor):
cell1 = create_solution_cell("hello", "code", "foo")
Expand All @@ -37,8 +37,8 @@ def test_duplicate_solution_cell(self, preprocessor):

nb, resources = preprocessor.preprocess(nb, {})

assert nb.cells[0].metadata.nbgrader == {}
assert nb.cells[1].metadata.nbgrader != {}
assert nb.cells[0].metadata.nbgrader != {}
assert nb.cells[1].metadata.nbgrader == {}

def test_duplicate_locked_cell(self, preprocessor):
cell1 = create_locked_cell("hello", "code", "foo")
Expand All @@ -49,5 +49,5 @@ def test_duplicate_locked_cell(self, preprocessor):

nb, resources = preprocessor.preprocess(nb, {})

assert nb.cells[0].metadata.nbgrader == {}
assert nb.cells[1].metadata.nbgrader != {}
assert nb.cells[0].metadata.nbgrader != {}
assert nb.cells[1].metadata.nbgrader == {}

0 comments on commit 05ca3f4

Please sign in to comment.