Source code

nbchkr.utils.add_checks(nb_node: dict, source_nb_node: dict, answer_tag_regex=None) dict[source]

Given a nb_node and a source source_nb_node, add the cells in nb_node with tags matching answer_tag_regex to source_nb_node

This is used to add a student’s answers to the source notebook.

nbchkr.utils.check(nb_node: dict, timeout: int = 600, score_regex_pattern=None, answer_tag_pattern=None) Tuple[int | None, int | None, str, dict][source]

Given a nb_node, it executes the notebook and keep track of the score.

This returns 4 things:

  • The student score

  • The total score obtainable

  • Some feedback in markdown format

  • A dictionary mapping check description tags to a boolean

nbchkr.utils.check_tags_match(source_nb_node: dict, nb_node: dict, tag_seperator: str = '|', tag_regex=None) bool[source]

This checks if the count of tags that match tag_regex on each cell matches. Note that it does not necessarily guarantee that the tags are on the same cells.

nbchkr.utils.get_description(cell: dict, description_regex_pattern=None, tag_seperator: str = '|') str[source]

Given a cell of a notebook, return the description as defined by the description_regex_pattern.

nbchkr.utils.get_score(cell: dict, score_regex_pattern=None) int[source]

Given a cell of a notebook, return the score as defined by the score_regex_pattern.

nbchkr.utils.get_tags(cell: dict, tag_seperator: str = '|', tag_regex=None) str[source]

Given a cell of a notebook, return a string with all tags that match tag_regex separated by |. Path | str, as_version: int = 4) dict[source]

Read a jupyter notebook file at nb_path.

Returns the python dict representation.

nbchkr.utils.remove_cells(nb_node, tags_regex_patterns_to_ignore=None, solution_regex=None, solution_repl=None)[source]

Given a dictionary representation of a notebook, removes:

  • Cells with tags matching patterns in tags_regex_patterns_to_ignore

  • Text in cells matching the solution_regex pattern.

Returns the python dict representation.

nbchkr.utils.write(output_path: Path, nb_node: dict)[source]

Write the python dict representation of a notebook to output_path.