A set of tools for nb handling
Project description
nb_helpers
A simple tool to clean, test and fix notebooks for your repo
Install
You can install from pypi:
pip install nb_helpers
or get latest:
pip install -e .
Usage
This little library gives you command line tools to clean, test and check your jupyter notebooks.
- Clean: When you call
clean_nbsit will strip notebooks from the metadata, this helps prevent git conflicts. You can also pass the flag--clear_outsand also remove cell outputs.
$ nb_helpers.clean_nbs --help tcapelle at MBP14.local (-)(main)
usage: nb_helpers.clean_nbs [-h] [--path PATH] [--clear_outs] [--verbose]
Clean notebooks on `path` from useless metadata
options:
-h, --help show this help message and exit
--path PATH The path to notebooks (default: .)
--clear_outs Remove cell outputs (default: False)
--verbose Rnun on verbose mdoe (default: False)
You can run this comman on this repo:
$ nb_helpers.clean_nbs
>
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓
┃ Notebook Path ┃ Status ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━┩
│ tests/data/dummy_folder/fail_nb.ipynb │ Ok✔ │
│ tests/data/dummy_folder/test_nb2.ipynb │ Ok✔ │
│ tests/data/dummy_folder/test_nb_all_slow.ipynb │ Ok✔ │
│ tests/data/dummy_folder/test_nb_some_slow.ipynb │ Ok✔ │
│ tests/data/features_nb.ipynb │ Ok✔ │
│ tests/data/test_nb.ipynb │ Ok✔ │
└─────────────────────────────────────────────────┴────────┘
- Run: One can run the notebooks in
pathand get info about the execution.
$ nb_helpers.run_nbs --help tcapelle at MBP14.local (-)(main)
usage: nb_helpers.run_nbs [-h] [--path PATH] [--verbose] [--flags FLAGS] [--timeout TIMEOUT] [--lib_name LIB_NAME] [--no_run] [--post_issue]
options:
-h, --help show this help message and exit
--path PATH A path to nb files (default: .)
--verbose Print errors along the way (default: False)
--flags FLAGS Space separated list of flags
--timeout TIMEOUT Max runtime for each notebook, in seconds (default: 600)
--lib_name LIB_NAME Python lib names to filter, eg: tensorflow
--no_run Do not run any notebook (default: False)
--post_issue Post the failure in github (default: False)
You get the following output inside this repo:
$ nb_helpers.run_nbs
CONSOLE.is_terminal(): True
Writing output to run.csv
| Notebook Path | Status | Run Time | colab |
|---|---|---|---|
| dev_nbs/search.ipynb | Fail | 1 s | open |
| tests/data/dummy_folder/fail_nb.ipynb | Fail | 1 s | open |
| tests/data/dummy_folder/test_nb2.ipynb | Ok | 0 s | open |
| tests/data/dummy_folder/test_nb_all_slow.ipynb | Skipped | 0 s | open |
| tests/data/dummy_folder/test_nb_some_slow.ipynb | Ok | 0 s | open |
| tests/data/features_nb.ipynb | Ok | 0 s | open |
| tests/data/test_nb.ipynb | Ok | 0 s | open |
- Summary:
You can get a summary of the notebooks in your project with the
nb_helpers.summary_nbsfunction.
$ nb_helpers.summary_nbs
CONSOLE.is_terminal(): True
Writing output to /Users/tcapelle/wandb/nb_helpers/logs/summary.csv
Reading 6 notebooks
┌───┬─────────────────────────────────────────────────┬────────────┬────────────────┬────────────────────────────────────────────────┬────────────┬───────┐
│ # │ nb name │ tracker │ wandb features │ python libs │ colab_cell │ colab │
├───┼─────────────────────────────────────────────────┼────────────┼────────────────┼────────────────────────────────────────────────┼────────────┼───────┤
│ 1 │ tests/data/dummy_folder/fail_nb.ipynb │ │ │ │ │ open │
│ 2 │ tests/data/dummy_folder/test_nb2.ipynb │ │ │ │ │ open │
│ 3 │ tests/data/dummy_folder/test_nb_all_slow.ipynb │ │ │ time │ │ open │
│ 4 │ tests/data/dummy_folder/test_nb_some_slow.ipynb │ │ │ time │ │ open │
│ 5 │ tests/data/features_nb.ipynb │ │ │ typing, itertools │ │ open │
│ 6 │ tests/data/test_nb.ipynb │ 0: tracker │ │ os, sys, logging, pathlib, fastcore, itertools │ 1 │ open │
└───┴─────────────────────────────────────────────────┴────────────┴────────────────┴────────────────────────────────────────────────┴────────────┴───────┘
Python Lib
All this functions can also be used inside python:
from pathlib import Path
from nb_helpers.run import run_nbs
examples_path = Path("examples/colabs")
errors = run_nbs(path=examples_path, verbose=True, timeout=600)
Also the library has many little functions to make your life easier inside the repo you are orchestrating:
from pathlib import Path
from nb_helpers.utils import *
from nb_helpers.colab import *
examples_path = Path("examples/colabs")
# get all nbs in the folder recursevely, filters hidden, non nb stuff
nb_files = find_nbs(example_path)
one_nb_path = nb_files[0]
notebook = read_nb(one_nb_path)
# get all libs imported
libs = detect_imported_libs(notebook)
# get remote github repo
github_repo = git_origin_repo(one_nb_path)
# detect if master is called main or master
master_name = git_main_name(one_nb_path)
# get colab link
colab_url = get_colab_url(one_nb_path, branch=master_name)
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nb_helpers-0.2.3.tar.gz.
File metadata
- Download URL: nb_helpers-0.2.3.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f17f403253c5dd4fee16491dea7a0eeeb11a4bf1e2cd2a86d82ef91eb0152e50
|
|
| MD5 |
d7634aed0ffa89f657969873b3ec909b
|
|
| BLAKE2b-256 |
4b55bd5d5f517cc8b6daf23aac9525b31f6863625ac55d30d8a39d42d1ddb8f4
|
File details
Details for the file nb_helpers-0.2.3-py3-none-any.whl.
File metadata
- Download URL: nb_helpers-0.2.3-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86ee6484fa29ddcf300a3c8c6d2a1d16d1439f6812fe55a0d5dbc21c8e5d977e
|
|
| MD5 |
ff9c5e3b9a10f1e287b1b434b99d5c93
|
|
| BLAKE2b-256 |
22fd51dabc9534dbecd568ee67509454566bec17c37b23b954ee134126539c3d
|