Lightweight running of notebooks without Papermill

nbrun[source]

nbrun(fname:Union[str, Path], flags=None)

Execute notebook and skip cells that have flags consistent tst_flags in settings.ini

_tmp_nb = _gen_nb()
assert '3157' not in _tmp_nb.read_text() #value does not exist before execution
_results = str(nbrun(_tmp_nb))
assert '3157' in _results # value exists after execution
assert '98343 + 2' in _results and '98345' not in _results # cells with flags do not get executed
running: test_files/exec.ipynb with kernel: python397jvsc74a57bd042fd40e048e0585f88ec242f050f7ef0895cf845a8dd1159352394e5826cd102

nbupdate[source]

nbupdate(fname:Union[str, Path], flags=None)

Run notebooks and update them in place.

_tmp_nb = _gen_nb()
assert '3157' not in _tmp_nb.read_text() # doesn't exist b/c notebook hasn't been run
nbupdate(_tmp_nb)
assert '3157' in _tmp_nb.read_text() # exists now b/c notebook has been run
running: test_files/exec.ipynb with kernel: python397jvsc74a57bd042fd40e048e0585f88ec242f050f7ef0895cf845a8dd1159352394e5826cd102
finished: test_files/exec.ipynb

parallel_nbupdate[source]

parallel_nbupdate(basedir:Union[Path, str], flags=None, recursive=True, n_workers=None, pause=0.1)

Run all notebooks in dir and save them in place.

_test_nb = _gen_nb()
assert not '3157' in _test_nb.read_text()
parallel_nbupdate(_test_nb)
assert '3157' in _test_nb.read_text()
running: test_files/exec.ipynb with kernel: python397jvsc74a57bd042fd40e048e0585f88ec242f050f7ef0895cf845a8dd1159352394e5826cd102
finished: test_files/exec.ipynb
All notebooks refreshed!

nbdoc_update[source]

nbdoc_update(srcdir:str=None, flags:str=None, n_workers:int=None, pause:float=0.5)

Refresh all notebooks in srcdir by running them and saving them in place.

Type Default Details
srcdir str None A directory of notebooks to refresh recursively, can also be a filename.
flags str None Space separated list of flags (tst_flags in settings.ini) to NOT ignore while running notebooks. Otherwise, those cells are ignored.
n_workers int None Number of workers to use
pause float 0.5 Pause time (in secs) between notebooks to avoid race conditions