bash_kernel
bash_kernel copied to clipboard
run another notebook
is there an easy way to have notebook2 run (like in source) the contents of notebook1 ?
my use case is rather simple; I have a rather long git tutorial, that I'd like to cut into pieces; of course ideally each notebook should be able to control the status of the git repo at the beginning, which can easily done by running the previous pieces
I remember I have done that with python notebooks occasionally, although it was admittedly abstruse; but well, asking does not cost anything, does it ? would be of tremendous help !
If you want them to run to write files and things, you can always run them from bash with something like jupyter nbconvert --execute.
If you want to run them and have variables etc. left in the bash namespace, I don't think there's currently a way to do that.
I was exploring this approach; I could manually convert a notebook into a bash file using the classic notebook UI and 'download file as' from the menubar; trying to automate further I was considering some sort of make-based approach to produce the .sh files out-of-band, but jupyter nbconvert --to bash does not seem to be an option, what am I missing ?
thanks !
--to script is the generic name for 'convert this notebook to a standard source code file for its kernel language'.
Oooook ! thanks a lot
You're welcome. I'd also be open to adding a function in bash_kernel called something like source-notebook which would take another notebook file, and run its code in the current kernel. I haven't looked into how much work that would involve, though.
a quick status on my end for the record:
at this point I have a simple makefile that updates one .sh file per notebook;
the .sh need to go into the git repo of course (I'm using s/t in the spirit of mybinder)
I can then invoke said .sh file with a formula like
bash 01-my-first-repo.sh >& /dev/null
- redirection is optional, it's just confusing to receive all the inputs without the markdown cells
- I'm invoking bash because I was too lazy to have the makefile do the
chmod +x
where should I start looking if I wanted to dig around your idea of a source-notebook ?
If you're running the scripts with bash (rather than source) afterwards, that should have a similar effect to running the notebooks with jupyter nbconvert --execute. It's probably a bit faster, though.
For source-notebook, I can see two ways to implement it:
- Write something (probably a bit of embedded Python to run from bash) that extracts the code from a notebook to a temp file, and then
sourcethat. - Pass the notebook path back to the Python kernel code somehow, and have it extract the cells and run them separately.