Giter Site home page Giter Site logo

Comments (30)

kiyoon avatar kiyoon commented on June 14, 2024

Thanks for the cool suggestion!

I think Jupyter Notebook doesn't provide me with the token with the API. I can launch the server but can't know the token. Maybe there's a way if I delve into their implementation..
A little hacky way is I can maybe infer the URL from the output and open it. I'll look into this.
In the meantime, you can use password rather than token. You can even diable the password completely, which will make it easier to connect.

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

You can supply a custom token for the server to use as an additional argument along with a bunch of other things:

jupyter notebook --NotebookApp.token=1234

The directory can be specified via the argument --NotebookApp.notebook_dir=dir or --NotebookApp.open_browser=False prevents the default browser from auto starting

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

@FelixKratz I originally thought about reading the URL but this looks simpler, although it will add some security risk. I think I will just make the command configurable and give you a default command template. I think the token has to be configurable also, but if it stays in the init.lua it is also a little risky

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

@FelixKratz I originally thought about reading the URL but this looks simpler, although it will add some security risk. I think I will just make the command configurable and give you a default command template. I think the token has to be configurable also, but if it stays in the init.lua it is also a little risky

If the token is generated somewhat randomly it should be fine, as it is only hosted on the loopback interface anyways.

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

The current :JupyniumStartAndAttachToServer doesn't really start syncing. Obviously because you need some manual input to open the notebook. I can make it till it opens the notebook but not sure if I should force start syncing. If it starts syncing, should I sync from the ipynb or from the ju.py? So many variables..

I think it makes sense to sync from the ju.py because it's the one that is open and you can check before the command. How do you think?

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

If I have a *.ju.py file open I could imagine that it would be nice to have a command that starts the notebook server, starts jupynium and starts syncing the file to the server, such that it is an all-in-one command. When the notebook server is run from jupynium directly there is no reason to wait with syncing, because no manual input is needed. Maybe a new command? Something like: JupyniumNotebookFromBuffer or something a bit shorter ^^

If a server is already running on 8888 this command should probably fall back to attaching to the server and syncing the new file to a new ipynb instance

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

I wanted to make commands as self-explanatory as possible so users have no confusion. Do you fuzzy-find the commands? I'm using wilder.nvim and I start server by typing :jara<tab> for example. I get that it sometimes gets too long though.
I can leave the current behaviour as is so that you can customise. You can make a custom function that calls both commands (or lua functions).
And maybe I can add the fallback behaviour when server is not available, it will open the server and open the notebook if it exists and start syncing.

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

I wanted to make commands as self-explanatory as possible so users have no confusion. Do you fuzzy-find the commands? I'm using wilder.nvim and I start server by typing :jara<tab> for example. I get that it sometimes gets too long though.
I can leave the current behaviour as is so that you can customise. You can make a custom function that calls both commands (or lua functions).
And maybe I can add the fallback behaviour when server is not available, it will open the server and open the notebook if it exists and start syncing.

Nice, at some point I will create a keyboard shortcut to execute these commands.

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

Another idea that I just had was that when the jupyter notebook process is started via jupynium in nvim it could be nice to have a popup window available in nvim that shows the console output of the jupyter notebook process. It is not important, but could be nice to have to check for the status of plugins etc.

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

By popup you mean another split or using something like plenary popup and make it look like Telescope? I've never used the popup feature before but in that case you can only see the output when it's open and you're not changing the buffer right?

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

I had something like telescope in mind, but this is something I would maybe use only once or twice a month to be honest.

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

This has been almost implemented (except the popup stuff).

You can try the feat/autostart-notebook branch (branch = 'feat/autostart-notebook' on packer) to test it out before it gets released.

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

Now this is done. Thank you for the awesome feedback!

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

First of all, thank you for adding this awesome feature! It is really nice.

I have noticed a problem however, it seems that the auto sync is not working, a tab appears and then instantly closes again:

bug.mp4

This is my config:

require("jupynium").setup({
  -- Conda users:
  -- python_host = "~/miniconda3/envs/jupynium/bin/python",
  python_host = vim.g.python3_host_prog or "python3",

  default_notebook_URL = "localhost:8888",

  -- Open the Jupynium server if it is not already running
  -- which means that it will open the Selenium browser when you open this file.
  -- Related command :JupyniumStartAndAttachToServer
  auto_start_server = {
    enable = true,
    file_pattern = { "*.ju.*" },
  },

  -- Attach current nvim to the Jupynium server
  -- Without this step, you can't use :JupyniumStartSync
  -- Related command :JupyniumAttachToServer
  auto_attach_to_server = {
    enable = true,
    file_pattern = { "*.ju.*", "*.md" },
  },

  -- Automatically open an Untitled.ipynb file on Notebook
  -- when you open a .ju.py file on nvim.
  -- Related command :JupyniumStartSync
  auto_start_sync = {
    enable = true,
    file_pattern = { "*.ju.*", "*.md" },
  },

  -- Automatically keep filename.ipynb copy of filename.ju.py
  -- by downloading from the Jupyter Notebook server.
  -- WARNING: this will overwrite the file without asking
  -- Related command :JupyniumDownloadIpynb
  auto_download_ipynb = false,

  -- Always scroll to the current cell.
  -- Related command :JupyniumScrollToCell
  autoscroll = {
    enable = true,
    mode = "always", -- "always" or "invisible"
    cell = {
      top_margin_percent = 20,
    },
  },

  scroll = {
    page = { step = 0.5 },
    cell = {
      top_margin_percent = 20,
    },
  },

  use_default_keybindings = true,
  textobjects = {
    use_default_keybindings = true,
  },

  -- Dim all cells except the current one
  -- Related command :JupyniumShortsightedToggle
  shortsighted = false,
})

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

Oh, sorry for the trouble. I tested it on Mac also and it's working okay for me..
So if you don't autostart the server and start syncing, it works?

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

If I press 'n' it works

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

You mean if you press 'n', and then again run :JupyniumStartSync it works?
I want to know if it's a problem caused by that function, or from the autostarting logic.
I can't reproduce it now. Do you use Mac Homebrew python 3.10 or above? There's a bug that will be fixed from the pip side, which breaks the installation on mac. Maybe that's affecting this too (like maybe some files are not correctly installed)

Maybe can you try building with pip3 install -e . or /usr/bin/pip3 install .?

Or is it possible to run with CLI nvim --listen /tmp/jupy_nvim and jupynium --nvim_listen_addr /tmp/jupy_nvim and paste the output here?

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

You mean if you press 'n', and then again run :JupyniumStartSync it works? I want to know if it's a problem caused by that function, or from the autostarting logic. I can't reproduce it now. Do you use Mac Homebrew python 3.10 or above? There's a bug that will be fixed from the pip side, which breaks the installation on mac. Maybe that's affecting this too (like maybe some files are not correctly installed)

Maybe can you try building with pip3 install -e . or /usr/bin/pip3 install .?

Or is it possible to run with CLI nvim --listen /tmp/jupy_nvim and jupynium --nvim_listen_addr /tmp/jupy_nvim and paste the output here?

No, if I press 'n' it works without doing anything else. So 'n' does what I thought 'y' would.

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

That's bizarre. It doesn't happen to me. 'n' opens a file and start syncing as well? I need to investigate why that happens

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

That's bizarre. It doesn't happen to me. 'n' opens a file and start syncing as well? I need to investigate why that happens

Yes, here is a video of that:

bug.mp4

There is another problem, when the .ju.py file does not exist yet and is only opened via nvim test.ju.py it hangs completely

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

That's really funny..

else:
sync_input = nvim.eval(
f"""input("There is no notebook {sync_ipynb_name}. Do you want to create and start syncing? (y/n): ")"""
)
if sync_input in ["y", "Y"]:
nvim.lua.Jupynium_start_sync(
bufnr, sync_ipynb_name, False, async_=True
) # bufnr, filename, ask

As you can see it should only do something when the input is y. Also can't really reproduce the hanging issue. What's your python version (I'm assuming Homebrew python 3.10)? I'll test on mac again and will come back to you.

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

python version is

 # python --version
Python 3.9.7

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

Is that the one that installed Jupynium?

Will this work?

python -m jupynium --version

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

Is that the one that installed Jupynium?

Will this work?

python -m jupynium --version
 # python -m jupynium --version
Jupynium v0.1.dev20+g3b86f69

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

Maybe there is something strange going on in my neovim....

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

Version looks fine. Mine is Jupynium v0.1.1.dev41+g3b86f69 (I didn't know the formatting of version is different on different system) but the commit is at least the same

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

I finally reproduced. I'll see and let you know. Sorry for the hassle

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

The issue is when auto_start_sync is enabled it will start syncing on top of the fallback sync behaviour together. That's why n will sync normally as well and y clashes

from jupynium.nvim.

FelixKratz avatar FelixKratz commented on June 14, 2024

Ah yes, that makes sense!

from jupynium.nvim.

kiyoon avatar kiyoon commented on June 14, 2024

It should be fixed now by #25

from jupynium.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.