Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should Jupyter extensions be installed and enabled for being reproducible?

I'd like to make interactive slide set (for a presentation with some live coding in python) with RISE a.k.a. live_reveal, which is a notebook extension for Jupyter.

I'd like the slide set to be usable by others (and by my future self) without too many manual steps (and without relying on hosted Jupyter solutions), thus I've chosen pipenv to manage dependencies.

I can get started with

pipenv install RISE
pipenv run jupyter nbextension install rise --py --sys-prefix
pipenv run jupyter nbextension enable rise --py --sys-prefix
pipenv run jupyter notebook  # to start the jupyter server

However, only pipenv install RISE leaves traces in the local directory (in Pipfile and Pipfile.lock). So, when using my files on a new machine (or after pipenv --rm) just

pipenv install
pipenv run jupyter notebook

won't suffice. The two nbextension steps will have to be repeated to enable the RISE extension and have the button available in Jupyter notebooks to switch to presentation mode.

Can this be automated? (Without employing additional tools like conda, docker, vagrant, make or other build systems, ...) If so, how should it be automated?

Can I tell pipenv (e.g. in Pipfile) to run these two commands after package installation? Or should I let the notebook (the *.ipynb file) load the extensions somehow?

like image 226
das-g Avatar asked Nov 07 '22 11:11

das-g


1 Answers

This is out of scope for pipenv. Pipenv manages your python environment - i.e., which packages are installed - and really nothing more. (The one exception to this is that environment variables in a .env file are loaded on pipenv run or pipenv shell commands). The nbextension commands you listed in your question are actually not dealing with the python environment at all, but are moving javascript and css files around (install rise) and creating (or editing, if you had other nbextensions installed) a json config file (enable rise).

For better or for worse, pipenv does not have anything like a postinstall hook for running arbitrary build commands. Nor does jupyter seem to have a way to prepackage or automatically install extensions, although I may be wrong about that.

My personal opinion is that making this sort of thing repeatable is exactly what the build tools you mentioned are great for. Your best bet without using a build tools of the sort you mentioned you would rather not use is to write a clear readme or maybe your own (documented) postinstall shell script.

like image 170
philngo Avatar answered Nov 14 '22 21:11

philngo