kiyoon / jupynium.nvim

Selenium-automated Jupyter Notebook that is synchronised with NeoVim in real-time.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Untitled.ipynb artifacts

sho-87 opened this issue · comments

Currently, every time you sync a ju file it will instantly create an artifact Untitled.ipynb file in the working directory. What this means is that the user must go in and clean up after themselves, otherwise the directory will be littered with old files, and can get especially bad if user is syncing multiple files at the same time

image

I think it's currently intended for Jupynium to create untitled files on sync, but might be worth re-evaluating this workflow following the discussions in #44

Possible solutions might be:

  • Load the related .ipynb file (if exists) when syncing instead of creating an untitled one
  • If an untitled files does get created, delete it for the user when stopping sync or stopping the server (could be a bit dangerous if the user, for some reason, just doesnt name their notebooks and has some important/useful ones lying around)

I thought about finding the correct filename by default, but since it shouldn't delete the file without noticing, it should ask if the file already exists.

This may not be ideal for people who want to just use a tmp dir to sync. In that case you don't care about overwriting so the current behaviour is more desirable for some people.

So I need to probably change the default to find the correct filename, and then still add an option to make untitled names.

I can do something like

:JupyniumStartSync [filename / tab_idx / --untitled] and if the argument is not provided, it just finds the file with the same name. If the argument is --untitled it will be like the current behaviour.

that would make sense

another option might be to use the system tmp directory so it doesnt clutter the working directory, and will get wiped on reboot. and have a setting to opt in to filename syncing (although like you said, maybe that should just be the default anyway)

See #23 if you want to just open the notebook server to the temp dir. The only problem is that it won't keep the notebook's directory the same as the file, so if you want to have some file operations you want to use absolute paths

Does this solution with different notebook dir work for you? Or you'd still want to make :JupyniumStartSync default to the current file name?

I didnt think about the issue of notebook and ju file having different directories. I think in this case syncing to the current filename ipynb would be nice to avoid clutter

Hi, sorry for taking so long to respond.
I suppose this is already possible.

If you start sync with a name, it will open the file instead of creating a new notebook.
If you want to sync with a current name, it is as simple as

filename_wo_ext = vim.fn.expand "%:r:r"
vim.cmd([[JupyniumStartSync ]] .. filename_wo_ext)

It is not an officially supported API (so it might change in the future), but you can also use a lua function

---Start synchronising the buffer with the ipynb file
---@param bufnr integer buffer number
---@param ipynb_filename string name of the ipynb file
---@param ask boolean whether to ask for confirmation
function Jupynium_start_sync(bufnr, ipynb_filename, ask)

So you can do something like

filename_wo_ext = vim.fn.expand "%:r:r"
Jupynium_start_sync(0, filename_wo_ext, false)

ah yes, thats a nice simple solution. will use that from now on!