/demo

Primary LanguagePythonApache License 2.0Apache-2.0

nbdev

Setup

The steps below outline how I set up this demo.

Conda environment

To get started, I first create a conda environment with everything I'll need:

mamba create -yn demo python quarto jupyterlab jupyterlab_vim jupytext nbdev black r-irkernel
mamba activate demo

Prior to running the command above, I installed the mambaforge Python distribution via homebrew and set up my shell to use the mamba command:

brew install mambaforge
mamba init zsh

Actually, that was a lie. My setup is much more automated than that :)

I have a setup script that doubles as the README.md of my setup repository.

The setup script also installs the carbonyl https://github.com

From nbdev, I only use the git and Jupyter hooks.

Running nbdev_install_hooks results in 4 changes:

  1. Add Python code to ~/.jupyter/jupyter_notebook_config.py and ~/.jupyter/jupyter_server_config.py:
def nbdev_clean_jupyter(**kwargs):
    try: from nbdev.clean import clean_jupyter
    except ModuleNotFoundError: return
    clean_jupyter(**kwargs)

c.ContentsManager.pre_save_hook = nbdev_clean_jupyter
  1. Add a .gitconfig file to the current repository:
# Generated by nbdev_install_hooks
#
# If you need to disable this instrumentation do:
#   git config --local --unset include.path
#
# To restore:
#   git config --local include.path ../.gitconfig
#
[merge "nbdev-merge"]
	name = resolve conflicts with nbdev_fix
	driver = nbdev_merge %O %A %B %P
  1. Replace .git/hooks/post-merge.sample with .git/hooks/post-merge in the current repository:
nbdev_trust
  1. Add a .gitattributes file to the current repository:
*.ipynb merge=nbdev-merge

pre-commit

The nbdev docs discuss pre-commit and provide a .pre-commit-config.yaml file:

repos:
- repo: https://github.com/fastai/nbdev
  rev: 2.2.10
  hooks:
  - id: nbdev_clean
  - id: nbdev_export

I decided to add my own pre-commit hook to the mix:

for q in *.qmd; do; quarto convert $q; quarto render $q; done;