Validation of Jupyter notebooks and kernels
Project description
JUPYTER NOTEBOOK VALIDATION
PROJECT OVERVIEW
This repository contains scripts used to validate ipynb notebooks and Jupyter kernels.
There is another related repository which contains a large number of test ipynb notebooks and routines to help with the execution of the validation tests via docker images and slurm batch jobs:
PACKAGE
A python package has been created which can be installed via pip or conda:
GOALS
The goals of this project are to be able to:
- Execute validation of Jupyter kernels using ipynb notebooks in the terminal
- Execute validations non-interactively in a CI pipeline
- Check execution output for errors
- Compare output of an execution to known output
- Select different Jupyter kernels to use
- Log results of notebook executions and tests
EXAMPLE OUTPUT
Partial output from validation tests run in the terminal:
Output from an ipynb notebook created from failed execution of a notebook:
INSTALL
The jnbv module can be installed with pip or conda using one of the following:
INSTALL WITH PIP
Create a virtual environment if you don't already have one:
python3 -m venv venv
Activate your environment, in this example it's in venv/:
source venv/bin/activate
Install the code from PyPi using pip:
pip install jnbv
Or install from gitlab using pip and git:
pip install git+https://gitlab.com/MAXIV-SCISW/JUPYTERHUB/jnbv.git
With either method, dependencies will also be installed.
INSTALL WITH CONDA
Activate and install directly into your environment:
source venv/bin/activate
conda install jnbv -c conda-forge
Or, you can add jnbv via your conda environment yaml file, by adding conda-forge to your list of channels, and jnbv to your list of dependencies, as in this example file:
---
name: my-conda-env
channels:
- conda-forge
dependencies:
- jnbv
Then update your conda environment, for example the base conda environment which is in the directory venv/:
venv/bin/conda env update --name base --file my-conda-env.yml
USAGE
jnbv -h
EXECUTE NOTEBOOK
For this, you will need to have:
- A base environment in which jnbv has been installed (see above)
- An ipynb notebook file
- A Jupyter kernel that will be used to execute the file
Once you have all these items, the base environment should be activated:
source venv/bin/activate
Check to see what kernels you have available:
jupyter kernelspec list
Available kernels:
hdf5-kernel /var/www/jupyterhub/jnbv/venv/share/jupyter/kernels/hdf5-kernel
python3 /var/www/jupyterhub/jnbv/venv/share/jupyter/kernels/python3
If you don't have any kernels, then install ipykernel into your environment with either pip or conda:
pip install ipykernel
conda install ipykernel
and then you should have the default kernel "python3" available.
If you don't have an ipynb notebook handy, you can get an example notebook file here:
wget https://gitlab.com/MAXIV-SCISW/JUPYTERHUB/jnbv/-/raw/master/development/the-meaning-of-life.ipynb
And then the ipynb notebook can be executed in the terminal, using the default kernel python3 for example:
jnbv the-meaning-of-life.ipynb \
--kernel python3 \
--execute
READ NOTEBOOK
By defualt, the result of executing an ipynb file is a new ipynb file named output.ipynb. It can be read in the terminal with:
jnbv output.ipynb --read
TEST NOTEBOOK
The same file can be checked for errors:
jnbv output.ipynb --test
COMPARE NOTEBOOKS
And two ipynb notebooks can be compared:
jnbv output.ipynb --compare the-meaning-of-life.ipynb
EXECUTE, TEST, COMPARE, SAVE
All steps can be made to run in succession with one command:
jnbv the-meaning-of-life.ipynb \
--kernel python3 \
--execute --read --test --compare --save
Or, more simply using the --validate option, which is a combination of 5 other options:
jnbv the-meaning-of-life.ipynb \
--kernel python3 \
--validate
Note that above the option --save was also added, which then creates the output
directory test-results/, and within that creates subdirectories with kernel
names, date stamps, and finally log files and new ipynb files.
For example:
test-results/
└── python3/
└── 2021-06-11_14-39-40/
├── the-meaning-of-life.ipynb
└── the-meaning-of-life.log
Example output from executing a simple notebook using the default kernel:
CONTRIBUTING
Would you like to contribute to this project? See: CONTRIBUTING.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file jnbv-2024.11.18.tar.gz
.
File metadata
- Download URL: jnbv-2024.11.18.tar.gz
- Upload date:
- Size: 2.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7c3cb1ca0df9c4e9d5bf9796fbd51635851dd98cc77c2adcd03689dea0c28eb |
|
MD5 | 59c8d1cc1eb930af658fe4ff1efd5635 |
|
BLAKE2b-256 | 8ad2795cc9a59741b77e71c9dae2cdc6abdce69414651f1a4e1cf78bbb8225ae |
File details
Details for the file jnbv-2024.11.18-py3-none-any.whl
.
File metadata
- Download URL: jnbv-2024.11.18-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e605452bf107a5387369b29e317a2ee57e8c52b64539fbf7059f222c0c3b2016 |
|
MD5 | e5eb5322bb98510031c57f2439323270 |
|
BLAKE2b-256 | a87303f4e0e75d09a975169d7c740b25788c5b90501bcc82df4f1344dbb3944e |