The internals for the lib2nbdev functionality

Foundational Helper Functions

code_cell[source]

code_cell(code:str=None)

Returns a Jupyter cell with potential code

A very simplistic and foundational function, it simply returns a string representation of a Jupyter cell without any metadata and potentially some code.

write_module_cell[source]

write_module_cell()

Writes a template Markdown cell for the title and description of a notebook

init_nb[source]

init_nb(module_name:str)

Initializes a complete blank notebook based on module_name

Also writes the first #default_exp cell and checks for a nested module (moduleA.moduleB)

write_cell[source]

write_cell(code:str, is_public:bool=False)

Takes source code, adds an initial #export tag, and writes a Jupyter cell

This function will write a cell given some code (which is a str). is_public is there to determine if #export or #exporti should be used (a public or private function, class, or object).

write_nb[source]

write_nb(splits:list, num:int, parent:str=None, private_list:list=[])

Writes a fully converted Jupyter Notebook based on splits and saves it in Config's nbs_path.

The notebook number is based on num

parent denotes if the current notebook module is based on a parent module such as moduleA.moduleB

private_list is a by-cell list of True/False for each block of code of whether it is private or public

Converting Libraries

convert_lib[source]

convert_lib()

Converts existing library to an nbdev one by autogenerating notebooks.

Optional prerequisites:

  • Make a nbdev settings.ini file beforehand
  • Optionally you can add # Cell and # Internal Cell tags in the source files where you would like specific cells to be

Run this command in the base of your repo

Can only be run once

An example of adding in # Cell or # Internal Cell to the source code can be seen below:

# Filename is noop.py

# Internal Cell
def _myPrivateFunc(o): return o

# Cell
def myPublicFunc(o): return o