Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def preprocess_cell(self, cell, resources, cell_index):
if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell):
cell.source = re.sub('{}(?:.|\n)*?{}'.format(self.hidestart,
self.hideend)
, '', cell.source)
# we probably don't really need this?
cell.metadata.nbgrader['oldchecksum'] = cell.metadata.nbgrader['checksum']
cell.metadata.nbgrader['checksum'] = utils.compute_checksum(cell)
return cell, resources
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int) -> Tuple[NotebookNode, ResourcesDict]:
if not (utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell)):
return cell, resources
grade_id = cell.metadata.nbgrader['grade_id']
if grade_id in self.grade_ids:
self.log.warning("Cell with id '%s' exists multiple times!", grade_id)
cell.metadata.nbgrader = {}
else:
self.grade_ids.add(grade_id)
return cell, resources
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
# compute checksums of grade cell and solution cells
if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell):
checksum = utils.compute_checksum(cell)
cell.metadata.nbgrader['checksum'] = checksum
cell.metadata.nbgrader['cell_type'] = cell.cell_type
if utils.is_grade(cell) or utils.is_solution(cell):
self.log.debug(
"Checksum for %s cell '%s' is %s",
cell.metadata.nbgrader['cell_type'],
cell.metadata.nbgrader['grade_id'],
checksum)
return cell, resources
def preprocess_cell(self, cell, resources, cell_index):
if utils.is_grade(cell):
self._create_grade_cell(cell)
if utils.is_solution(cell):
self._create_solution_cell(cell)
if utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell):
self._create_source_cell(cell)
return cell, resources
def _get_type_changed_cells(self, nb: NotebookNode) -> typing.List[NotebookNode]:
changed = []
for cell in nb.cells:
if not (utils.is_grade(cell) or utils.is_solution(cell) or utils.is_locked(cell)):
continue
if 'cell_type' not in cell.metadata.nbgrader:
continue
new_type = cell.metadata.nbgrader.cell_type
old_type = cell.cell_type
if new_type and (old_type != new_type):
changed.append(cell)
return changed
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
# replace solution regions with the relevant stubs
language = resources["language"]
replaced_solution = self._replace_solution_region(cell, language)
# determine whether the cell is a solution/grade cell
is_solution = utils.is_solution(cell)
# check that it is marked as a solution cell if we replaced a solution
# region -- if it's not, then this is a problem, because the cell needs
# to be given an id
if not is_solution and replaced_solution:
if self.enforce_metadata:
raise RuntimeError(
"Solution region detected in a non-solution cell; please make sure "
"all solution regions are within solution cells."
)
# replace solution cells with the code/text stub -- but not if
# we already replaced a solution region, because that means
# there are parts of the cells that should be preserved
if is_solution and not replaced_solution:
if cell.cell_type == 'code':
def preprocess_cell(self,
cell: NotebookNode,
resources: ResourcesDict,
cell_index: int
) -> Tuple[NotebookNode, ResourcesDict]:
if (self.lock_solution_cells or self.lock_grade_cells) and utils.is_solution(cell) and utils.is_grade(cell):
cell.metadata['deletable'] = False
elif self.lock_solution_cells and utils.is_solution(cell):
cell.metadata['deletable'] = False
elif self.lock_grade_cells and utils.is_grade(cell):
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
elif self.lock_readonly_cells and utils.is_locked(cell):
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
elif self.lock_all_cells:
cell.metadata['deletable'] = False
cell.metadata['editable'] = False
return cell, resources