Hacker News new | ask | show | jobs
by westurner 471 days ago
To have tests that can be copied or exported into a .py module from a notebook is advantageous for prototyping and reusability.

There are exploratory/discovery and explanatory forms and workflows for notebooks.

A typical notebook workflow: get it working with Ctrl-Enter and manually checking output, wrap it in a function(s) with defined variable scopes and few module/notebook globals, write a test function for the function which checks the output every time, write markdown and/or docstrings, and then what of this can be reused from regular modules.

nbdev has an 'export a notebook input cell to a .py module' feature. And formatted docstrings like sphinx apidoc but in notebooks. IPython has `%psource module.py` for pygments-style syntax highlighting of external .py modules and `%psave output.py` for saving an input cell to a file, but there are not yet IPython magics to read from or write to certain lines within a file like nbdev.

To run the chmp/ipytest %%ipytest cell magic with line or branch coverage, it's necessary to `%pip install ipytest pytest-cov` (or `%conda install ipytest pytest-cov`)

jupyter-xeus supports environment.yml with jupyterlite with packages from emscripten-forge: https://jupyterlite-xeus.readthedocs.io/en/latest/environmen...

emscripten-forge src: https://github.com/emscripten-forge/recipes/tree/main/recipe... .. web: https://repo.mamba.pm/emscripten-forge