NotebookParser

class NotebookParser(original_notebook_paths: list[str] | None = None)[source]

Main parsing class for notebooks.

NotebookParser utilizes that instance and class attributes are separated and class attributes allow sharing of information across instances. This is used to realize the mapping of checked parsed notebooks back to their original files.

Initialize NotebookParser.

Initializing an instance of the class will save original_notebook_paths, which is a List of paths to notebooks, to the class attributes, which can be accessed by all instances or all modules that know about the class. If original_notebook_paths isn’t provided, the class attributes will stay as it was.

Parameters:

original_notebook_paths (List[str], optional) – List of paths to notebooks, by default None

Attributes Summary

input_line_mappings

List of input_line_mapping

intermediate_py_file_paths

List of paths to the parsed Notebooks

original_notebook_paths

List of paths to the original Notebooks

temp_path

Path of the temp folder the parsed notebooks were saved in

Methods Summary

clean_up

Delete the created temporary directory if it exists and resets all class attributes.

create_intermediate_py_file_paths

Create intermediate files needed for analysis.

get_mappings

Return the mapping information needed to generate error messages.

Methods Documentation

static clean_up() None[source]

Delete the created temporary directory if it exists and resets all class attributes.

create_intermediate_py_file_paths() None[source]

Create intermediate files needed for analysis.

Parses all notebooks provided by self.original_notebook_paths and saves them to a temporary directory, if original_notebook_paths, was provided at initialization.

static get_mappings() Iterator[tuple[str, str, InputLineMapping]][source]

Return the mapping information needed to generate error messages.

The message corresponds to the original notebook and not the actually checked parsed one.

Returns:

(original_notebook_paths, intermediate_py_file_paths, input_line_mappings) original_notebook_paths is the relative path of the tested notebook. intermediate_py_file_paths is the absolute path of the checked notebook. And input_line_mapping is a dict of information about which input in the original notebook, is in what line in the corresponding pared notebook.

Return type:

Iterator[tuple[str, str, InputLineMapping]]

See also

input_line_mapping, create_intermediate_py_file