Package: nb-helpers
nb_helpersA simple tool to clean, test and fix notebooks for your repoInstallYou can install from pypi:pipinstallnb_helpersor get latest:pipinstall-e.UsageThis little library gives you command line tools to clean, test and check your jupyter notebooks.Clean: When you callclean_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--helptcapelleatMBP14.local(-)(main)usage:nb_helpers.clean_nbs[-h][--pathPATH][--clear_outs][--verbose]Cleannotebookson`path`fromuselessmetadata

options:-h,--helpshowthishelpmessageandexit--pathPATHThepathtonotebooks(default:.)--clear_outsRemovecelloutputs(default:False)--verboseRnunonverbosemdoe(default:False)You can run this comman on this repo:$nb_helpers.clean_nbs
>┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┓┃NotebookPath┃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 inpathand get info about the execution.$nb_helpers.run_nbs--helptcapelleatMBP14(--)(main)usage:nb_helpers.run_nbs[-h][--verbose][--lib_nameLIB_NAME][--no_run][--pip_install][--github_issue][--repoREPO][--ownerOWNER][path]positionalarguments:pathApathtonbfiles(default:/Users/tcapelle/wandb/nb_helpers)options:-h,--helpshowthishelpmessageandexit--verbosePrinterrorsalongtheway(default:False)--lib_nameLIB_NAMEPythonlibnamestofilter,eg:tensorflow--no_runDonotrunanynotebook(default:False)--pip_installRuncellswith!pipinstall(default:False)--github_issueCreateagithubissueifnotebookfails(default:False)--repoREPOGithubrepotocreateissuein(default:nb_helpers)--ownerOWNERGithubownertocreateissuein(default:wandb)You can now post github issues when running fails, the cool thing is that it can be posted to another repo than the one from the notebooks. Just pass the--reponame and the--owner(for examplewandb/other_cool_repo)You get the following output inside this repo:$nb_helpers.run_nbs
CONSOLE.is_terminal():True
Writingoutputtorun.csvNotebook PathStatusRun Timecolabdev_nbs/search.ipynbFail1 sopentests/data/dummy_folder/fail_nb.ipynbFail1 sopentests/data/dummy_folder/test_nb2.ipynbOk0 sopentests/data/dummy_folder/test_nb_all_slow.ipynbSkipped0 sopentests/data/dummy_folder/test_nb_some_slow.ipynbOk0 sopentests/data/features_nb.ipynbOk0 sopentests/data/test_nb.ipynbOk0 sopenSummary:
You can get a summary of the notebooks in your project with thenb_helpers.summary_nbsfunction.$nb_helpers.summary_nbs
CONSOLE.is_terminal():True
Writingoutputto/Users/tcapelle/wandb/nb_helpers/logs/summary.csv
Reading6notebooks
┌───┬─────────────────────────────────────────────────┬────────────┬────────────────┬────────────────────────────────────────────────┬────────────┬───────┐
│# │ 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 LibAll this functions can also be used inside python:frompathlibimportPathfromnb_helpers.runimportrun_nbsexamples_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:frompathlibimportPathfromnb_helpers.utilsimport*fromnb_helpers.colabimport*examples_path=Path("examples/colabs")# get all nbs in the folder recursevely, filters hidden, non nb stuffnb_files=find_nbs(example_path)one_nb_path=nb_files[0]notebook=read_nb(one_nb_path)# get all libs importedlibs=detect_imported_libs(notebook)# get remote github repogithub_repo=git_origin_repo(one_nb_path)# detect if master is called main or mastermaster_name=git_main_name(one_nb_path)# get colab linkcolab_url=get_colab_url(one_nb_path,branch)