Git Product home page Git Product logo

nbmake's Introduction

nbmake

codecov PyPI versions PyPI versions Twitter PyPI Downloads Gitpod ready-to-code

What? Pytest plugin for testing and releasing notebook documentation

Why? To raise the quality of scientific material through better automation

Who is this for? Research/Machine Learning Software Engineers who maintain packages/teaching materials with documentation written in notebooks.

Functionality

  1. Executes notebooks using pytest and nbclient, allowing parallel notebook testing
  2. Optionally writes back to the repo, allowing faster building of nbsphinx or jupyter book docs

Quick Start

pip install pytest nbmake
pytest --nbmake **/*ipynb

Allow errors and Configure Cell Timeouts

Each notebook can be configured to allow errors and fail if running exceeds a timeout.

This configuration must be placed in the notebook's top-level metadata (not cell-level metadata).

Your notebook should look like this:

{
  "cells": [ ... ],
  "metadata": {
    "kernelspec": { ... },
    "execution": {
      "allow_errors": true,
      "timeout": 300
    }
  }
}

Add Missing Jupyter Kernel to Your CI Environment

If you are using a kernel name other than the default ‘python3’. You will see an error message when executing your notebooks in a fresh CI environment: Error - No such kernel: 'mycustomkernel'

Use ipykernel to install the custom kernel:

python -m ipykernel install --user --name mycustomkernel

If you are using another language such as c++ in your notebooks, you may have a different process for installing your kernel.

Parallelisation

Parallelisation with xdist is experimental upon initial release, but you can try it out:

pip install pytest-xdist

pytest --nbmake -n=auto

It is also possible to parallelise at a CI-level using strategies, see example

Build Jupyter Books Faster

Using xdist and the --overwrite flag let you build a large jupyter book repo faster:

pytest --nbmake --overwrite -n=auto examples
jb build examples

Advice on Usage

nbmake is best used in a scenario where you use the ipynb files only for development. Consumption of notebooks is primarily done via a docs site, built through jupyter book, nbsphinx, or some other means. If using one of these tools, you are able to write assertion code in cells which will be hidden from readers.

Pre-commit

Treating notebooks like source files lets you keep your repo minimal. Some tools, such as plotly may drop several megabytes of javascript in your output cells, as a result, stripping out notebooks on pre-commit is advisable:

# .pre-commit-config.yaml
repos:
  - repo: https://github.com/kynan/nbstripout
    rev: master
    hooks:
      - id: nbstripout

See https://pre-commit.com/ for more...

Disable Nbmake

Implicitly:

pytest

Explicitly:

pytest -p no:nbmake

See Also:

nbmake's People

Contributors

alex-treebeard avatar github-actions[bot] avatar icetdrinker avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.