The Converter
Functions borrowed from old nbdev
Foundational Helper Functions
export_names
export_names (code, func_only=False)
Find the names of the objects, functions or classes defined in code
that are exported.
code_cell
code_cell (code:str=None)
Returns a Jupyter cell with potential code
nbglob
nbglob (fname=None, recursive=None, extension='.ipynb', config_key='nbs_path')
Find all files in a directory matching an extension given a config_key
.
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
write_module_cell ()
Writes a template Markdown
cell for the title and description of a notebook
init_nb
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
write_cell (code:str, is_public:bool=False)
Takes source code
, adds an initial #| export
or #| exporti
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
write_nb (cfg_path:str, cfg_name:str, 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
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