Package: jnbv
JUPYTER NOTEBOOK VALIDATIONProject OverviewInstallUsageContributingPROJECT OVERVIEWThis 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:jupyter-notebook-validationPACKAGEA python package has been created which can be installed via pip or conda:conda package:PyPi package:GOALSThe goals of this project are to be able to:Execute validation of Jupyter kernels using ipynb notebooks in the terminalExecute validations non-interactively in a CI pipelineCheck execution output for errorsCompare output of an execution to known outputSelect different Jupyter kernels to useLog results of notebook executions and testsEXAMPLE OUTPUTPartial output from validation tests run in the terminal:Output from an ipynb notebook created from failed execution of a notebook:INSTALLThe jnbv module can be installed with pip or conda using one of the following:conda package:PyPi package:gitlab repository:INSTALL WITH PIPCreate a virtual environment if you don't already have one:python3-mvenvvenvActivate your environment, in this example it's in venv/:sourcevenv/bin/activateInstall the code fromPyPiusing pip:pipinstalljnbvOr install from gitlab using pip and git:pipinstallgit+https://gitlab.com/MAXIV-SCISW/JUPYTERHUB/jnbv.gitWith either method, dependencies will also be installed.INSTALL WITH CONDAActivate and install directly into your environment:sourcevenv/bin/activate
condainstalljnbv-cconda-forgeOr, 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:-jnbvThen update your conda environment, for example the base conda environment
which is in the directory venv/:venv/bin/condaenvupdate--namebase--filemy-conda-env.ymlUSAGEjnbv-hEXECUTE NOTEBOOKFor this, you will need to have:A base environment in which jnbv has been installed (see above)An ipynb notebook fileA Jupyter kernel that will be used to execute the fileOnce you have all these items, the base environment should be activated:sourcevenv/bin/activateCheck to see what kernels you have available:jupyterkernelspeclistAvailablekernels:hdf5-kernel/var/www/jupyterhub/jnbv/venv/share/jupyter/kernels/hdf5-kernelpython3/var/www/jupyterhub/jnbv/venv/share/jupyter/kernels/python3If you don't have any kernels, then install ipykernel into your environment
with either pip or conda:pipinstallipykernel
condainstallipykerneland 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:wgethttps://gitlab.com/MAXIV-SCISW/JUPYTERHUB/jnbv/-/raw/master/development/the-meaning-of-life.ipynbAnd then the ipynb notebook can be executed in the terminal, using the default
kernel python3 for example:jnbvthe-meaning-of-life.ipynb\--kernelpython3\--executeREAD NOTEBOOKBy defualt, the result of executing an ipynb file is a new ipynb file named
output.ipynb.  It can be read in the terminal with:jnbvoutput.ipynb--readTEST NOTEBOOKThe same file can be checked for errors:jnbvoutput.ipynb--testCOMPARE NOTEBOOKSAnd two ipynb notebooks can be compared:jnbvoutput.ipynb--comparethe-meaning-of-life.ipynbEXECUTE, TEST, COMPARE, SAVEAll steps can be made to run in succession with one command:jnbvthe-meaning-of-life.ipynb\--kernelpython3\--execute--read--test--compare--saveOr, more simply using the --validate option, which is a combination of 5 other
options:jnbvthe-meaning-of-life.ipynb\--kernelpython3\--validateNote 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.logExample output from executing a simple notebook using the default kernel:CONTRIBUTINGWould you like to contribute to this project?
See:CONTRIBUTING.mdJNBV CHANGELOG2022.1.29 (2022-01-29)changelog now reverse chronological orderViewadded warning to ignoreView2022.1.26 (2022-01-26)added ignoring of some h5web outputViewbumped version in setup.cfg to 2022.1.26View2021.11.22 (2021-11-22)added to list of things to ignoreViewupdated notes on developemt workViewbumped version in setup.cfg to 2021.11.22View2021.11.4 (2021-11-04)added some timing keywords to the list of inputs to ignoreViewbumped version in setup.cfg to 2021.11.4Viewbumped version in setup.cfg to 2021.11.4View2021.10.26 (2021-10-26)added to list of source to ignoreViewupdateed execution of test notebookViewupdated the execution of a couple notebooksViewbumped version in setup.cfg to 2021.10.26View2021.8.26 (2021-08-26)updated licenseViewtrying to setup sastViewtry adding script to SAST jobViewtrying againViewadded artifactsViewtry adding a gl-sast-report.json fileViewtry adding gl-sast-report.jsonViewtrying some other things...Viewtrying something elseViewtrying appthreat/sast-scanViewchanged before_script for sast jobViewchanged type to pythonViewchanged job nameViewtrying semgrepViewadded berfore_script to semgrep jobViewchange to semgrap commandViewtry some other semgrep settingsViewother semgrep settingsViewtrying to view artifactViewtrying other semgrep settingsViewtrying bandit for security testing, replaced assert statements with raise AssertionErrorViewadded pip installViewadding more to bandit checksViewchanged asserrt statment to comply with bandit errorsViewtrying different bandit commandViewchange to bandit scan triggerViewadded creation of bandit reportsViewbumped version in setup.cfg to 2021.8.26View2021.8.18 (2021-08-18)updated readmeViewadded a source line to ignoreViewadded combining of stderr outputsViewbumped version in setup.cfg to 2021.8.18View2021.8.17.1 (2021-08-17)added retry of ntoebook execution in case of kernel dyingViewadded comparison test, fixed mistake in execution functionViewadded special validation notebook for py36Viewbumped version in setup.cfg to 2021.8.17.1View2021.8.17 (2021-08-17)updated screenshotViewadded warning to ignoreViewbumped version in setup.cfg to 2021.8.17Viewbumped version in setup.cfg to 2021.8.17.1Viewslight change to versioning setupViewfixed typoViewbumped version in setup.cfg to 2021.8.17View2021.8.16.0 (2021-08-16)small changes to commentsViewadded function for removal of warnings in cell outputViewsmall change to outputViewremoved old commentsViewadded a couple tests and dependencies needed in kernel environmentsViewhad forgotten to add removal of warnings from both outputs when doing comparisonsViewadded another wanring to ignore, added check for existance of subkeyViewbumped version in setup.cfg to 2021.8.16.0View2021.8.4.0 (2021-08-04)reorganization of tests in tox configurationViewsmall edits of documentationViewbumped version in setup.cfg to 2021.8.4.0View2021.8.3.0 (2021-08-03)added makefile targets for new tests, added badges to top of readmeViewupdated documentation a bitViewedited screenshots slightlyViewadded tests for reading of notebooksViewtry to make reading tests failViewchange to exection CI test triggersViewadded tests of test_ipynb functionViewfixed incorrect asserion testsViewadded a bit to the documentationViewadded simple changelog generator target to makefileViewadded comparison tests, combined some test executions in tox configViewfixed typo, changed some CI job namesViewcombined some tests in tox configViewchanged test function namesViewchanged some test namesViewfixed incorrect test name in CI configViewslight comment changeViewadded some commentsViewsmall change to comparison code, added a testViewsimplified validation tests, made comparison check for newline betterViewadded some more execution and validation testsViewtrying to get varsioning, tagging, and changelog to all work nice togetherViewbumped version in setup.cfg to 2021.8.3.0Viewbumped version in setup.cfg to 2021.8.3.0View2021.7.28.0 (2021-07-28)cropped screenshotsViewcreated pytest for executionViewfixed mistake in tox test, added to documentationViewfixed some documentation mistakesViewsmall edits of documentationViewchange to CI triggers, slimmed test_execute_success_hdf5_kernel()Viewadded various tests of notebook executionViewsome changes to execution testsViewfixed incorrect namesViewchanged test names, making CI more compactViewbumped version in setup.cfg to 2021.7.28.0View2021.7.21.3 (2021-07-21)updated documentationViewupdated documentationViewbumped version in setup.cfg to 2021.7.21.3View2021.7.21.2 (2021-07-21)created makefile target to upload to PyPi, altered CI to upload to PyPiViewbumped version in setup.cfg to 2021.7.21.2View2021.7.21.1 (2021-07-21)bumped version in setup.cfg to 2021.7.21.1View2021.7.21.0 (2021-07-21)have commit counts start at 0 instead of 1Viewbumped version in setup.cfg to 2021.7.21.0View2021.7.19.9 (2021-07-19)made link to CONTRIBUTING.md accessible from pypi pageViewbumped version in setup.cfg to 2021.7.19Viewbumped version in setup.cfg to 2021.7.19_8fe57776Viewbumped version in setup.cfg to 2021.7.19.7976e902Viewbumped version in setup.cfg to 2021.7.19.dev6ccdf2a1Viewbumped version in setup.cfg to 2021.7.19_5Viewbumped version in setup.cfg to 2021.7.19-6Viewbumped version in setup.cfg to 2021.7.19.7Viewbumped version in setup.cfg to 2021.7.19.8Viewupdated documentationViewbumped version in setup.cfg to 2021.7.19.9View2021.7.19 (2021-07-19)updated readme, added comments to yaml filesViewfixed typosViewchanged triggers for some CI stagesViewmaking png image pypi friendlyViewbumped version in setup.cfg to 2021.7.19View2021.7.16 (2021-07-16)re-grouping of makefile targets, new screenshotViewupdated documentationViewsmall change to target and stage nameViewadded a bit to the documentationViewbumped version in setup.cfg to 2021.7.16View2021.7.15 (2021-07-15)small comment editViewcreated test of jnbv terminal executionViewadded new jnbv temrinal execution test to CIViewtry unpinning version in env yamlViewremove basepython configurationViewremoved some modules, try to figure out issueViewtry adding back in validation testViewipykenrel is needed, but seems to be the source of issue when installing in gitlab CIViewtry adding validation test againViewcleaned up some comments, changed makefile target namesViewcreated a validation test for use with pytestViewpytest excution working with all versions of pythonViewfixed incorrect test env nameViewsplit testing environments - one for basic building, the other for testing of a kernelViewupdated instructions and screenshotViewbumped version in setup.cfg to 2021.7.15View2021.7.12 (2021-07-12)some cleaning up of nested if-statements, added example hdf5 kernel, notebook, dataViewsome more cleaning upViewmax-complexity in flake8 now 10Viewa bit more if-nesting removalViewadded sourcing of conda env prior to test executionViewbumped version in setup.cfg to 2021.7.12ViewBSD 2-Clause LicenseCopyright (c) 2021, Jason Brudvik, MAX IV LaboratoryRedistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.