Notes about nbdev
- Notes based on the nbdev2 introductory video tutorial
- Notes based on How nbdev helps us structure our data science workflow in Jupyter Notebooks
- Quarto
-
YouTube tutorial
- Create a Github repo
- Terminal:
nbdev_helpto list help - Terminal:
nbdev_newfrom git folder - Open Jupyter lab and edit files
settings.iniand.ipynbabout module and index page -
nbdev_exportto export notebooks to python modules -
pip install -e .to install package in development mode -
nbdev_previewto preview package documentation - use anottations such as
#| hideand#| exportto control behavior - use
@patchto add methods to previously defined classes. Good for sequentially testing and documenting the code- When the method is defined directly in the class we can add documentation by using
show_doc(<class_name>.<method_name>)
- When the method is defined directly in the class we can add documentation by using
-
nbdev_test: run test locally. We can useassert,test_eq,test_neand the like to write the tests- We can add
#!notestat the beginning of the cell to skip the cell during test.
- We can add
- Use
%debugto debug your code - Golden rule when developing with nbdev: cells should either contain import general code to be exported, but not a mixture of the two
-
nbdev_clean: clean notebook metadata. Suggested before sending to GitHub.- There are hooks that can do that automatically. Look at the docs.
-
nbdev_prepare: run export, clean and test -
nbdev_pypi: upload to pypi - Nice GitHub action to review notebooks in PR: https://github.com/marketplace/review-notebook-app
- Post link: This post is based on nbdev1
nbdev2 is based on Quarto. It is recommended to read the documentation to understand what features are available.