A place to keep some common code

Cells can be hidden (with #hide). Cells with code that we want to export get an #export flag and will be placed into whatever file is specified in the first cell (core.py in this case). All other cells are treated as tests and will be executed as part of the CI included with NBDEV. In some cases we don't want to run cells every time - they can be marked with #slow or #skiptest and going forward will then only be run if we explicitly decide to do this.

Let's start by exporting some demo code:

demo_code[source]

demo_code()

We can run this code:

demo_code()
'demo'

To make this a 'test' is simple:

assert str(demo_code()) == 'demo'

Here's a cell that I want to run now but would be too slow for testing. In fact, it's one I never want to run:

import time # This import should really be in a separate cell, especially if time is used elsewhere
time.sleep(10)

We can export the code from these notebooks and build the docs from the command line, but it is also useful to export the code from within the notebook. So the last cell here does just that:

from nbdev.export import notebook2script; notebook2script()
Converted 00_core.ipynb.
Converted 01_Cairo_Hello.ipynb.
Converted 02_Meeting_Mice.ipynb.
Converted 03_Augmenting_Animals.ipynb.
Converted 05_Playing_with_Perlin.ipynb.
Converted 06_Interaction_with_ipycanvas.ipynb.
Converted 07_Doing_some_documentation.ipynb.
Converted 09_Data_Bubbles.ipynb.
Converted 10_Going_3D.ipynb.
Converted index.ipynb.