SciRuby / iruby

Official gem repository: Ruby kernel for Jupyter/IPython Notebook
https://github.com/SciRuby/iruby
MIT License
901 stars 29 forks source link

Question: Is it possible to preload some ruby script when initializing kernel? #355

Open simpl1g opened 2 weeks ago

simpl1g commented 2 weeks ago

We have script with some useful methods/settings to work with in notebooks, but we manually doing require in each notebook, is it possible to load it automatically when kernel is starting? Maybe so hooks available?

rstammer commented 2 weeks ago

I think what you need here is to write your own specialized Jupypter notebook kernel based on the iruby kernel, kinda an extension of the default iruby kernel. That sounds more monstrous as it is in the end, I think, as the "definition" of a kernel is basically a JSON config.

I cannot explain it completely, but maybe here's a hint how to approach it: In the project Jupyter on Rails there is logic that creates a special kernel in between that loads an entire Rails application.

In the same fashion you should be able to construct a kernel file that loads the files you need as your custom kernel. Maybe this rake task is a good starting point for further research.

Good luck!

simpl1g commented 2 weeks ago

@rstammer Thanks! yep, I already looked how Jupyter on Rails does this and decided to ask if it possible to do without json manipulations :)