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:

  1. Reads the notebook into UnparsedCell objects

  2. Parses and processes the unparsed cells into ParsedMarkdownCell and ParsedCodeCell objects accordingly. This yields a tree of ModuleNode objects representing the resulting file-structure.

  3. Writes the packages and modules given the parsed ModuleNode tree.

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