dccsillag / magma-nvim

Interact with Jupyter from NeoVim.
GNU General Public License v3.0
988 stars 50 forks source link

Connect externally to the kenel #57

Open manu0600 opened 2 years ago

manu0600 commented 2 years ago

Hello,

First of all i must say your plugin is absolutely amazing !! Thanks for the efforts

Is is possible to connect externally to the kernel of Magma ? After running MagmaInit, I would like to be able to connect to the kernel by opening a second terminal and running jupyter console --existing xxxx (where xxxx is the kernel number), but I don't see any kernel open in ~/.local/share/jupyter/runtime/ so I don't know how to do this

Thank you

dccsillag commented 1 year ago

First of all i must say your plugin is absolutely amazing !! Thanks for the efforts

Thank you!

Is is possible to connect externally to the kernel of Magma ? After running MagmaInit, I would like to be able to connect to the kernel by opening a second terminal and running jupyter console --existing xxxx (where xxxx is the kernel number), but I don't see any kernel open in ~/.local/share/jupyter/runtime/ so I don't know how to do this

Huh, you should be able to do this. Maybe I have to add some flag to when I start the Jupyter kernel?

I'm a bit short on time right now, but as soon as I'm able to I'll look into this.

manu0600 commented 1 year ago

I found the way to do it, but I don't know how to automate it (implement it to a keyboard shortcut) :

Paste the above JSON into a file, and connect with: $> jupyter --existing or, if you are local, you can connect with just: $> jupyter --existing /tmp/tmp8_1oeodg.json or even just: $> jupyter --existing if this is the most recent Jupyter kernel you have started.


- The kernel file is `/tmp/tmp8_1oeodg.json`

Could you maybe run that command at the end of MagmaInit and extract the location of the kernel file (in this case `/tmp/tmp8_1oeodg.json` to have it accessible in a variable (let's say `kernel_file`) ?
This way i could either print it, and open it manually, or automate something with a floating terminal like
[toggleterm.nvim](https://github.com/akinsho/toggleterm.nvim)
manu0600 commented 1 year ago

Another way to find the kernel file path is using ps aux, where the output should look something like :

/.../bin/python3 -m ipykernel_launcher -f /tmp/tmp8_1oeodg.json

Since MagmaInit is launching this command, it should be "easy" to put the location of this kernel file in a variable I guess, but I don't know where to look for it in the source code

usmcamp0811 commented 1 year ago

I was toying with this some as I explore Magma.. but something as silly and simple as ls -t /tmp/*.json | head -n1 would give you the newest json and if its run as soon as Magma starts the kernel.. its a pretty good chance its the correct file.. and thats not hard to throw into a lua function.