Is it possible to define a custom (cell) magic
See original GitHub issueThis is more of an inquiry/research question: I recently started playing around with Jep a bit and found it quite useful for combining the Java image processing library ImgLib2 and Kotlin extensions/operators with NumPy ndarray in native CPython. This all works with shared memory, really cool! I learned about library descriptors, which I could use to add Jep and a Python interpreter to the Kernel. Users could then call
interpreter.exec
and similar functions to execute their Python code.
Then I thought, maybe I can mark an entire cell as Python code via some custom cell magic, and the magic handler would then pass the Python code to the Python interpreter object that the Kernel holds. To make this work, I would need some way (that may or may not exist) to add a custom cell magic. Before I spend more time on it, I would like to know if something like that would be possible, in principle, or if I would be wasting my time.
Thank you!
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (2 by maintainers)
Hello @hanslovsky! Currently the list of magics is fixed and not extensible, but your idea is really cool. I think that I can implement even a more powerful way of doing it — custom code preprocessor which takes the whole cell code before the execution and can change it in any way. In your case it will wrap the cell code to the interpreter.exec() call.
I was also able to create a library definition the proper way (example notebooks in the repo). I am really happy with how this turned out. Thanks again!