Processor#
(nbrefactor.processor.processor)
Notebook-refactoring processor
- process_notebook(notebook_path, output_path, root_package='.', pre_write_hook=None, generate_init=False)[source]#
The Notebook-refactoring entry point. This function:
Reads the notebook into
UnparsedCellobjectsParses and processes the unparsed cells into
ParsedMarkdownCellandParsedCodeCellobjects accordingly. This yields a tree ofModuleNodeobjects representing the resulting file-structure.Writes the packages and modules given the parsed
ModuleNodetree.
- Parameters:
notebook_path (str) – the full path to the Notebook file.
output_path (str) – the desired output path for the refactored project.
root_package (str, optional) – the root package for the refactored project (defaults to ‘.’; i.e. root level of the given output_path).
write_hook (callable, optional) – a hook function that takes (content, node) and returns the modified content.
generate_init (bool, optional) – whether to generate __init__.py files in package directories. Defaults to False.
- Returns:
the root node of the generated tree structure.
- Return type:
ModuleNode