Giter Site home page Giter Site logo

kiyoon / jupynium.nvim Goto Github PK

View Code? Open in Web Editor NEW
408.0 8.0 14.0 219 KB

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

License: MIT License

Lua 38.54% Vim Script 0.11% Shell 0.03% Python 59.31% JavaScript 1.40% Scheme 0.61%
vim nvim nvim-plugin jupyter-notebook neovim neovim-plugin neovim-plugins nvim-plugins

jupynium.nvim's Introduction

Jupynium: Control Jupyter Notebook on Neovim with ZERO Compromise

It's just like a markdown live preview, but it's Jupyter Notebook live preview!

Jupynium uses Selenium to automate Jupyter Notebook, synchronising everything you type on Neovim.
Never leave Neovim. Switch tabs on the browser as you switch files on Neovim.

Note that it doesn't sync from Notebook to Neovim so only modify from Neovim.

How does it work?

The Jupynium server will receive events from Neovim, keep the copy of the buffer and apply that to the Jupyter Notebook by using Selenium browser automation. It interacts only through the front end so it doesn't require installing extensions on the kernel etc., which makes it possible to:

  • Develop locally, run remotely (or vice versa)
  • Use university-hosted Jupyter Notebook
  • Use any other languages / kernels such as R

πŸ› οΈ Installation

Requirements

  • πŸ’» Linux, macOS and Windows (CMD, PowerShell, WSL2)
  • ✌️ Neovim >= v0.8
  • 🦊 Firefox
    • Other browsers are not supported due to their limitation with Selenium (see #49)
  • 🦎 Mozilla geckodriver
    • May already be installed with Firefox. Check geckodriver -V
  • 🐍 Python >= 3.7
    • Supported Python installation methods include system-level and Conda
  • πŸ“” Jupyter Notebook >= 6.2
    • Jupyter Lab is not supported
    • # jupyter-console is optional and used for `:JupyniumKernelOpenInTerminal`
      pip install notebook nbclassic jupyter-console

Important note about Notebook 7 (breaking change!)

Jupynium does not support Notebook 7 yet. In the meantime, you can change the default_notebook_URL = "localhost:8888/nbclassic" in require("jupynium").setup({ ... }) to use the classic (Notebook 6) interface with Jupynium. This is the new default setting from now on.

Don't forget to upgrade your notebook and install nbclassic (pip install --upgrade notebook nbclassic) when you set this.

Install Python

Don't have system Python 3.7? You can use Conda:

conda create -n jupynium python=3
conda activate jupynium

Upgrade pip. This solves many problems:

# pip >= 23.0 recommended
pip3 install --upgrade pip

Install Jupynium

Click to see vim-plug and packer installation.

With vim-plug:

Plug 'kiyoon/jupynium.nvim', { 'do': 'pip3 install --user .' }
" Plug 'kiyoon/jupynium.nvim', { 'do': 'conda run --no-capture-output -n jupynium pip install .' }
Plug 'rcarriga/nvim-notify'   " optional
Plug 'stevearc/dressing.nvim' " optional, UI for :JupyniumKernelSelect

With packer.nvim:

use { "kiyoon/jupynium.nvim", run = "pip3 install --user ." }
-- use { "kiyoon/jupynium.nvim", run = "conda run --no-capture-output -n jupynium pip install ." }
use { "rcarriga/nvim-notify" }   -- optional
use { "stevearc/dressing.nvim" } -- optional, UI for :JupyniumKernelSelect

With πŸ’€lazy.nvim:

  {
    "kiyoon/jupynium.nvim",
    build = "pip3 install --user .",
    -- build = "conda run --no-capture-output -n jupynium pip install .",
    -- enabled = vim.fn.isdirectory(vim.fn.expand "~/miniconda3/envs/jupynium"),
  },
  "rcarriga/nvim-notify",   -- optional
  "stevearc/dressing.nvim", -- optional, UI for :JupyniumKernelSelect

Configure Jupynium

The default configuration values are below and work well for system-level Python users. If you're a Conda user, you need to change python_host to execute using the conda command instead.

Click to see the setup defaults
require("jupynium").setup({
  --- For Conda environment named "jupynium",
  -- python_host = { "conda", "run", "--no-capture-output", "-n", "jupynium", "python" },
  python_host = vim.g.python3_host_prog or "python3",

  default_notebook_URL = "localhost:8888/nbclassic",

  -- Write jupyter command but without "notebook"
  -- When you call :JupyniumStartAndAttachToServer and no notebook is open,
  -- then Jupynium will open the server for you using this command. (only when notebook_URL is localhost)
  jupyter_command = "jupyter",
  --- For Conda, maybe use base environment
  --- then you can `conda install -n base nb_conda_kernels` to switch environment in Jupyter Notebook
  -- jupyter_command = { "conda", "run", "--no-capture-output", "-n", "base", "jupyter" },

  -- Used when notebook is launched by using jupyter_command.
  -- If nil or "", it will open at the git directory of the current buffer,
  -- but still navigate to the directory of the current buffer. (e.g. localhost:8888/nbclassic/tree/path/to/buffer)
  notebook_dir = nil,

  -- Used to remember the last session (password etc.).
  -- e.g. '~/.mozilla/firefox/profiles.ini'
  -- or '~/snap/firefox/common/.mozilla/firefox/profiles.ini'
  firefox_profiles_ini_path = nil,
  -- nil means the profile with Default=1
  -- or set to something like 'default-release'
  firefox_profile_name = nil,

  -- 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 = false,
    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 = false,
    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 = true,

  -- Automatically close tab that is in sync when you close buffer in vim.
  auto_close_tab = true,

  -- 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,
    },
  },

  -- Files to be detected as a jupynium file.
  -- Add highlighting, keybindings, commands (e.g. :JupyniumStartAndAttachToServer)
  -- Modify this if you already have lots of files in Jupytext format, for example.
  jupynium_file_pattern = { "*.ju.*" },

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

  syntax_highlight = {
    enable = true,
  },

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

  -- Configure floating window options
  -- Related command :JupyniumKernelHover
  kernel_hover = {
    floating_win_opts = {
      max_width = 84,
      border = "none",
    },
  },
})

-- You can link highlighting groups.
-- This is the default (when colour scheme is unknown)
-- Try with CursorColumn, Pmenu, Folded etc.
vim.cmd [[
hi! link JupyniumCodeCellSeparator CursorLine
hi! link JupyniumMarkdownCellSeparator CursorLine
hi! link JupyniumMarkdownCellContent CursorLine
hi! link JupyniumMagicCommand Keyword
]]

-- Please share your favourite settings on other colour schemes, so I can add defaults.
-- Currently, tokyonight is supported.

Optionally, configure nvim-cmp to show Jupyter kernel completion

local cmp = require "cmp"
local compare = cmp.config.compare

cmp.setup {
  sources = {
    { name = "jupynium", priority = 1000 },  -- consider higher priority than LSP
    { name = "nvim_lsp", priority = 100 },
    -- ...
  },
  sorting = {
    priority_weight = 1.0,
    comparators = {
      compare.score,            -- Jupyter kernel completion shows prior to LSP
      compare.recently_used,
      compare.locality,
      -- ...
    },
  },
}

Optionally, configure nvim-ufo to fold cells

There is an API serving as a folds provider, which will return a table with format {startLine=#num, endLine=#num}.

require("jupynium").get_folds()

You should use it with a fold plugin like nvim-ufo.
See #88 for more detail and an example configuration.

πŸƒ Quick Start

  • Open a *.ju.py file.
  • Execute :JupyniumStartAndAttachToServer. This will open Jupyter Notebook on the Firefox browser.
    • If not, clarify option jupyter_command or just open the Notebook server by yourself: jupyter notebook
  • Execute :JupyniumStartSync. This will create an Untitled.ipynb file on the browser.
  • Now you can type # %% in Neovim to create a code cell.
    • You'll see everything you type below that will be synchronised in the browser.
    • Execute cells using the default keybind <space>x.

For detailed instructions, see Usage below.

🚦 Usage

There are 2 general steps to using Jupynium:

  1. Setup a Jupynium file
  2. Connect to the Jupynium server

The Jupynium server stays alive as long as the browser is alive. So you can see them as the same thing in this doc. For example:

  • Starting Jupynium server = opening a Selenium browser
  • Manually closing the browser = closing the Jupynium server

Setup a Jupynium file

Jupynium uses a Jupytext's percent format (see the Jupynium file format section below). This Jupytext file named .ju.py is what you will primarily be interacting with, rather than the .ipynb file directly. The contents of the Jupynium file are synced to the browser notebook where it can be viewed in real-time. If you want to keep a copy of the notebook, it can be downloaded as an .ipynb file later.

First, it's recommended to set a password on your notebook (rather than using tokens):

$ jupyter notebook password
Enter password: πŸ”’

$ jupyter notebook    # leave notebook opened

If you want to start a new notebook

  1. Manually create a local Jupynium file called <filename>.ju.py
  2. Done! The rest happens after connecting to the server

If you want to open an existing notebook

There are currently 2 ways of converting an existing .ipynb file to a Jupynium file:

Option 1: Use an included command line tool:

ipynb2jupytext [-h] [--stdout] [--code_only] file.ipynb [file.ju.py]

If you're already familiar with Jupytext, feel free to use it instead.

Option 2: This method requires that you have already connected to the Jupynium server:

  1. Open your .ipynb file in the web browser after connecting to the server
  2. In a new Neovim buffer, run :JupyniumLoadFromIpynbTab. This will convert the contents of the notebook file to Jupynium format.
  3. Save your buffer as <filename>.ju.py

When using Jupynium for the first time, it's recommended to start a new notebook to make sure everything works before trying to load existing files.

Connect to the Jupynium server

(This is for local Neovim only. For remote Neovim, see Command-Line Usage)

In Neovim, with your Jupynium .ju.py file open, you can run :JupyniumStartAndAttachToServer to start the notebook server.

Sync current buffer to the Jupynium server

You need to be on the main notebook page (file browser) for the next few steps.

Although Neovim is now attached to the server, it won't automatically start syncing.

To sync your Neovim Jupynium file to a notebook, run :JupyniumStartSync.

You can also:

  • :JupyniumStartSync filename to give a name to the notebook (filename.ipynb) instead of Untitled.ipynb. This does not open existing files. If a file with that name already exists then the filename argument will just be ignored.
  • To sync a Jupynium file to an existing notebook, manually open the file in the browser, and :JupyniumStartSync 2 to sync to the 2nd tab (count from 1).

At this point, any changes you make within the Neovim Jupynium file will be reflected live in the browser. Make sure you do not make changes inside the browser itself, as the sync is only one-way (from Neovim to browser).

If you want to save a copy of the .ipynb file, run :JupyniumDownloadIpynb. There is also a configuration option to enable automatic downloading.

Sync multiple Jupynium files

You can sync multiple files at the same time. Simple run :JupyniumStartSync again with the new file you want to sync.

Use multiple Neovim

You can run :JupyniumStartSync on a new Neovim instance.
If you have auto_attach_to_server = false during setup, you need to run :JupyniumAttachToServer and :JupyniumStartSync.

πŸ“ Jupynium file format (.ju.py or .ju.*)

The Jupynium file format follows Jupytext's percent format. In order for Jupynium to detect the files, name them as *.ju.py or specify jupynium_file_pattern in require("jupynium").setup().

Code cell:
Any code below this line (and before the next separator) will be the content of a code cell.

  • # %%

Magic commands

  • # %time becomes %time in notebook.
  • If you want to really comment out magic commands, comment it two times like ## %time.

Markdown cell: Any code below this line will be markdown cell content.

  • # %% [md]
  • # %% [markdown]

In Python, the recommended way is to wrap the whole cell content as a multi-line string.

# %% [md]
"""
# This is a markdown heading
This is markdown content
"""

In other languages like R, you'll need to comment every line.

# %% [md]
# # This is a markdown heading
# This is markdown content

Explicitly specify the first cell separator to use it like a notebook.

  • If there is one or more cells, it works as a notebook mode.
    • Contents before the first cell are ignored, so use it as a heading (shebang etc.)
  • If there is no cell, it works as a markdown preview mode.
    • It will still open ipynb file but will one have one markdown cell.

⌨️ Keybindings

  • <space>x: Execute selected cells
  • <space>c: Clear selected cells
  • <PageUp>, <PageDown>: Scroll notebook
  • <space>js: Scroll to cell (if autoscroll is disabled)
  • <space>K: Hover (inspect a variable)
  • <space>jo: Toggle output scroll (when output is long)

If you want custom keymaps, add use_default_keybindings = false and follow M.default_keybindings() in lua/jupynium/init.lua.

Textobjects

  • [j, ]j: go to previous / next cell separator
  • <space>jj: go to current cell separator
  • vaj,vij, vaJ, viJ: select current cell
    • a: include separator, i: exclude separator
    • j: exclude next separator, J: include next separator

If you want custom keymaps, add textobjects = { use_default_keybindings = false } and follow M.default_keybindings() in lua/jupynium/textobj.lua.

πŸ“‘ Available Vim Commands

" Server (only used when Neovim is local. See Command-Line Usage for remote neovim)
:JupyniumStartAndAttachToServer [notebook_URL]
:JupyniumStartAndAttachToServerInTerminal [notebook_URL]    " Useful for debugging
:JupyniumAttachToServer [notebook_URL]

" Sync
:JupyniumStartSync [filename / tab_index]
:JupyniumStopSync
:JupyniumLoadFromIpynbTab tab_index
:JupyniumLoadFromIpynbTabAndStartSync tab_index

" Notebook (while syncing)
:JupyniumSaveIpynb
:JupyniumDownloadIpynb [filename]
:JupyniumAutoDownloadIpynbToggle

:JupyniumScrollToCell
:JupyniumScrollUp
:JupyniumScrollDown
:JupyniumAutoscrollToggle

:JupyniumExecuteSelectedCells
:JupyniumClearSelectedCellsOutputs
:JupyniumToggleSelectedCellsOutputsScroll

:JupyniumKernelRestart
:JupyniumKernelInterrupt
:JupyniumKernelSelect
:JupyniumKernelHover      " See value like LSP hover
:JupyniumKernelOpenInTerminal [hostname] " Connect to kernel of synchronized notebook

" Highlight
:JupyniumShortsightedToggle

Lua API

The core API is provided as a global function.

--- Execute javascript in the browser. It will switch to the correct tab before executing.
---@param bufnr: integer | nil If given, before executing the code it will switch to the tab of this buffer. Requires syncing in advance.
---@param code string Javascript code
---@return boolean, object: Success, response
Jupynium_execute_javascript(bufnr, code)

Example: get kernel name and language

-- Use bufnr=nil if you don't want to switch tab
local code = [[return [Jupyter.notebook.kernel.name, Jupyter.kernelselector.kernelspecs];]]
local status_ok, kernel_name_and_spec = Jupynium_execute_javascript(0, code)
if status_ok then
  local kernel_name = kernel_name_and_spec[1]   -- "python3"
  local kernel_spec = kernel_name_and_spec[2]
  local kernel_language = kernel_spec[kernel_name].spec.language  -- "python"
  local kernel_display_name = kernel_spec[kernel_name].spec.display_name  -- "Python 3 (ipykernel)"
end

πŸ‘¨β€πŸ’»οΈ Command-Line Usage (attach to remote Neovim)

You don't need to install the vim plugin to use Jupynium. The plugin is responsible of adding :JupyniumStartAndAttachToServer etc. that just calls the command line program, plus it has textobjects and shortsighted support.

Install Jupynium if you haven't already:

pip3 install jupynium

Open a python/markdown file with nvim and see :echo v:servername.
Run Jupynium like:

jupynium --nvim_listen_addr /tmp/your_socket_path

Or, you can run Neovim like

nvim --listen localhost:18898 notebook.ju.py

Then start Jupynium as well as attaching the neovim to it.

jupynium --nvim_listen_addr localhost:18898

Note that you can attach to remote neovim by changing localhost to servername.com or using SSH port forwarding.

This will open Firefox with Selenium, defaulting to http://localhost:8888/nbclassic.

Additionally,

  • You can run jupynium command multiple times to attach more than one Neovim instance.
  • jupynium --notebook_URL localhost:18888 to view different notebook.
  • You can just run jupynium without arguments to just leave the server / browser running and wait for nvim to attach.

⚠️ Caution

The program is in the alpha stage. If it crashes it's likely that the whole browser turns off without saving!

Rules

  1. Always leave the home page accessible. Jupynium interacts with it to open files. Do not close, or move to another website.
  • It's okay to move between directories.
  1. It's OK to close the notebook pages. If you do so, it will stop syncing that buffer.
  2. Changing tab ordering or making it to a separate window is OK.

πŸ€” FAQ

🌽 How do I use different languages / kernels?

Instead of *.ju.py if you make files named *.ju.* (e.g. *.ju.r) you will see all the keybindings and commands.
All the procedures should be the same.

The notebook content is not in sync with vim. How do I fix it?

You probably would have accidentally modified directly from the notebook.

  1. If you want to keep the vim content and sync to the notebook, just add one more cell in the notebook and start making changes in vim. It works because Jupynium tries to only update the currently modified cell if the number of cells is the same in both. If it differs, it will fully update the entire content.
  2. To keep the notebook content and load that to vim, run :JupyniumLoadFromIpynbTab [tab_index] without making changes on vim.

πŸ“° Fun Facts

  • I spent my whole Christmas and New Year holidays (and more) just making this plugin.
  • This is the star history chart with relevant plugins. Thank you for helping it grow!

Star History Chart

jupynium.nvim's People

Contributors

fecet avatar joh avatar juweeism avatar kiyoon avatar matthewsia98 avatar sho-87 avatar vandalt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jupynium.nvim's Issues

Auto-start the jupyter notebook server if none exists

I think it would be really cool if a jupyter notebook session could be started from within nvim, e.g.

  • I open a *.ju.py file in neovim
  • If there is no jupyer notebook server on 8888, jupynium starts a server for me and creates a self generated token, such that I don't have to enter it.
  • Selenium starts and automatically accesses the jupyter notebook server with the correct token
  • The corresponding ipynb is opened

Creating Jupytext markdown cells can cause notebook to crash

Describe the bug
Creating a markdown cell with the # %% [markdown] jupytext format can cause the notebook to crash if using snippets or adding the comment only after writing %% [markdown].

To Reproduce
Steps to reproduce the behavior:

  1. Open a jupynium file and sync it
  2. Create a markdown cell either with a snippet (e.g. with LuaSnip and nvim-cmp) or by first writing %% [markdown] and then adding # at the start of line.
  3. See error

Expected behavior
A markdown cell should be created in the notebook, as is the case when typing # %% [markdown] manually.

Output when using jupynium command
The output below is when using a snippet. to generate the cell.
One thing I noted is that the line right before the notebook call is

jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 4, 4]]

when crashing (both with snippet or when manually adding # after the rest), and

jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 1, 1]]

when working. The numbers at the end are different. I thought this might be the cause, though I have no idea what they mean, nor how the Selenium and Jupyter APIs work.

Crashing example jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, [''], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['m'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['ma'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mar'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/m'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/ma'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/mar'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/mark'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/markd'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/markdo'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/markdow'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/markdown'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['m'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['mark/markdown'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, [''], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markdown]'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markdown]'], 4, 5, 5]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 4, 4]] jupynium.buffer: 254 - INFO - Inserting cell 1 from Notebook jupynium.jupyter_notebook_selenium: 19 - INFO - New markdown (jupytext) cell created below cell 0 jupynium.buffer: 398 - INFO - Converting to markdown cells: [1, 2] jupynium.cmds.jupynium: 507 - ERROR - Uncaught exception occurred while processing events. Detaching nvim. Traceback (most recent call last): File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/cmds/jupynium.py", line 502, in main status, rpcrequest_event = process_events(nvim_info, driver) File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/events_control.py", line 217, in process_events prev_lazy_args_per_buf.process_all(nvim_info, driver) File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/events_control.py", line 137, in process_all lazy_args.process(nvim_info, driver, bufnr) File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/events_control.py", line 116, in process process_on_lines_event(nvim_info, driver, bufnr, self.on_lines_args) File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/events_control.py", line 546, in process_on_lines_event nvim_info.jupbufs[bufnr].process_on_lines( File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/buffer.py", line 134, in process_on_lines self._partial_sync_to_notebook( File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/jupynium/buffer.py", line 400, in _partial_sync_to_notebook driver.execute_script( File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 500, in execute_script return self.execute(command, {"script": script, "args": converted_args})["value"] File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute self.error_handler.check_response(response) File "/home/vandal/.local/pipx/venvs/jupynium/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.JavascriptException: Message: TypeError: string is undefined Stacktrace: splitLinesAuto<@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106f1684f27b88c5d6 f856ec07bf47f23b510f08badb65d627f757e61eca804345b:774:27 splitLines@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106f1684f27b88c5d6f856e c07bf47f23b510f08badb65d627f757e61eca804345b:6557:14 Doc.prototype<.setValue<@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106f1684f 27b88c5d6f856ec07bf47f23b510f08badb65d627f757e61eca804345b:6211:36 docMethodOp/<@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106f1684f27b88c5d6f8 56ec07bf47f23b510f08badb65d627f757e61eca804345b:4038:22 CodeMirror.prototype[prop]@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106f168 4f27b88c5d6f856ec07bf47f23b510f08badb65d627f757e61eca804345b:9845:40 TextCell.prototype.set_text@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106f16 84f27b88c5d6f856ec07bf47f23b510f08badb65d627f757e61eca804345b:59692:26 Notebook.prototype.transfer_to_new_cell@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653 112727106f1684f27b88c5d6f856ec07bf47f23b510f08badb65d627f757e61eca804345b:68324:21 Notebook.prototype.to_markdown@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112727106 f1684f27b88c5d6f856ec07bf47f23b510f08badb65d627f757e61eca804345b:68408:22 Notebook.prototype.cells_to_markdown@http://localhost:8888/static/notebook/js/main.min.js?v=bac2262d97e0eab7b445494fe686be11796512a6902a434d05aa653112 727106f1684f27b88c5d6f856ec07bf47f23b510f08badb65d627f757e61eca804345b:68391:18 @http://localhost:8888/notebooks/Untitled5.ipynb?kernel_name=comm8-plan:2:24 @http://localhost:8888/notebooks/Untitled5.ipynb?kernel_name=comm8-plan:3:8

[I 16:13:52.416 NotebookApp] Starting buffering for 929e72b9-1150-4ee6-9588-49430fe1eaf0:21863c760c7f45509e6789f6d9574497

Working example jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markd]'], 0, 1, 1]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 0, 0]] jupynium.buffer: 258 - INFO - Cell 0 type change to code from Notebook jupynium.buffer: 391 - INFO - Converting to code cells: [1] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markdo]'], 0, 1, 1]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 0, 0]] jupynium.buffer: 258 - INFO - Cell 0 type change to code from Notebook jupynium.buffer: 391 - INFO - Converting to code cells: [1] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markdow]'], 0, 1, 1]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 0, 0]] jupynium.buffer: 258 - INFO - Cell 0 type change to code from Notebook jupynium.buffer: 391 - INFO - Converting to code cells: [1] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markdown]'], 0, 1, 1]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 0, 0]] jupynium.buffer: 258 - INFO - Cell 0 type change to markdown (jupytext) from Notebook jupynium.buffer: 398 - INFO - Converting to markdown cells: [1] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 0, 0]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'on_lines', [1, ['# %% [markdown]', '# '], 0, 1, 2]] jupynium.events_control: 195 - INFO - Event from nvim: ['notification', 'CursorMovedI', [1, 1, 1]] jupynium.buffer: 258 - INFO - Cell 0 type change to markdown (jupytext) from Notebook jupynium.buffer: 398 - INFO - Converting to markdown cells: [1]

Output of jupynium --version

Jupynium v0.1.2.dev55+g8a1b2be.d20230311

Output of nvim --version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Can't figure out how to setup remote connection

Hello, thanks for creating this plugin! I have some issue setting up the connection in the remote neovim + local firefox setting for jupynium.

Here's what I tried:

  • in the remote, installed the jupynium.nvim plugin and launched the neovim with nvim --listen localhost:8080 test.ju.py
  • on my local machine, set up the jupynium env and installed all dependency packages and launched jupynium with jupynium --nvim_listen_addr localhost:8898
    with port forwarding for ssh:
Host ec2
	HostName xx
	User xx
	ProxyJump xx
	LocalForward 8898 127.0.0.1:8080

When the jupynium command runs, here's the terminal print:

jupynium.pynvim_helpers:   11 - INFO - nvim addr: localhost:8898
jupynium.pynvim_helpers:   30 - INFO - nvim attached
jupynium.pynvim_helpers:   34 - INFO - Initialising..
jupynium.pynvim_helpers:   35 - INFO - Communicating with channel_id 7
jupynium.cmds.jupynium:   90 - INFO - Using firefox profile: None
selenium.webdriver.common.selenium_manager:  115 - INFO - Executing: ~/.pyenv/versions/3.8.16/envs/jupynium/lib/python3.8/site-packages/selenium/webdriver/common/macos/selenium-manager --browser firefox --output json
[I 16:41:55.667 NotebookApp] 302 GET / (127.0.0.1) 0.330000ms
[I 16:41:55.673 NotebookApp] 302 GET /tree? (127.0.0.1) 0.390000ms

However, I see in the opened browser, the address is
image
(note: the port is 8888, not 8898)
It seems to started a local jupyter notebook instance instead of connecting to the remote. On the other hand, in the remote neovim, it does like there's some connection established with all the available commands:
image

I am not sure if I missed anything or did anything obviously wrong. Any help would be really appreciated thanks!

JupyniumStartSync RPC channel closed. Stop sending all notifications. And firefox not waking up

Describe the bug
I'm on Ubuntu WSL using pip install jupynium to install jupynium (This does not appear in the doc ... so I'm not sure if it's needed... )
I opened a file named test.ju.py as suggested in the quick start session and run :JupyniumStartAndAttachToServer

it shows [Jupynium]: Jupynium successfully attached and initialised. Run :JupyniumStartSync (also firefox does not spawn...)
I did as suggested . Run the command but then I was greeted with

Jupynium : RPC channel closed. Stop sending all notifications.
[Jupynium]: Cancelling sync.....

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
after running JupyniumStartAndAttachToServer, firefox windows should show up and then jupyniumstartsync should reflects what is edited in real time.

Output when using jupynium command
If you launch Jupynium server using the command line program, it gives you more helpful logs.

Paste the output here

Output of jupynium --version

Paste the output here

Output of nvim --version

Paste your output here

Additional context
Add any other context about the problem here.

Use google colab/kaggle notebooks

Hi! Thanks for creating this plugin, it works perfectly while running locally. But is there any way to attach neovim to the google colab, or kaggle notebook?

Package jupynium python library for NixOS distro

Is your feature request related to a problem? Please describe.
Unfortunately, NixOS stores all his packages, libraries and programs in read-only mode, which is not helping when working with pip. Usually, nixos' user will search for packaged library on the official NixOS search page with all other packages and programs and install it into their configuration.

I'm making this request because, the tutorial is perfect, I'm only missing the module jupynium.

Describe the solution you'd like
Packaging python package into Nixpkgs.

Additional context
A little tutorial for you to package it: Hacking Your First Package

Example with numpy: Numpy

Unable to attach nvim to server on Windows

I'm following the usage instructions and when I run :JupyniumStartAndAttachToServer in nvim, a window opens for a few seconds and closes - no browser or notebook appears

pip freeze shows that both jupynium and selenium packages are installed:

jupynium @ file:///C:/Users/Simon/AppData/Local/nvim-data/lazy/jupynium.nvim
selenium==4.8.0

Testing selenium from python also works OK:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://www.selenium.dev/selenium/web/web-form.html")

When I simply run jupynium from the terminal, firefox opens showing the notebook tree and the following info:

jupynium.cmds.jupynium:  439 - INFO - No nvim attached. Waiting for nvim to attach. Run jupynium --nvim_listen_addr /tmp/example (use `:echo v:servername` of nvim)

At this point, I go back to nvim and run :JupyniumAttachToServer but I get the following exception:

jupynium.cmds.jupynium:  225 - INFO - New nvim wants to attach: Namespace(attach_only=True, check_running=False, firefox_profile_name=None, firefox_profiles_ini_path=None, jupyter_command=['jupyter'], notebook_URL='http://localhost:8888/tree/', notebook_dir=None, nvim_listen_addr='\\\\\\\\.\\\\pipe\\\\nvim.24356.0', sleep_time_idle=0.05, version=False)
jupynium.pynvim_helpers:   11 - INFO - nvim addr: \\\\.\\pipe\\nvim.24356.0
jupynium.cmds.jupynium:  249 - ERROR - Exception occurred while attaching a new nvim. Ignoring.
Traceback (most recent call last):
  File "C:\Users\Simon\AppData\Roaming\Python\Python38\site-packages\jupynium\cmds\jupynium.py", line 230, in attach_new_neovim
    nvim = attach_and_init(new_args.nvim_listen_addr)
  File "C:\Users\Simon\AppData\Roaming\Python\Python38\site-packages\jupynium\pynvim_helpers.py", line 28, in attach_and_init
    raise TimeoutError("Timeout while waiting for nvim to start")
TimeoutError: Timeout while waiting for nvim to start

Not sure if this is related, but nvim doesn't seem to have access to any of the sync commands like JupyniumStartSync. it only sees these:

image

JupyniumStartSync sometimes leaves the ipynb empty

Minor bug that doesn't set the ipynb content from time to time.

Maybe happens when you move around during the :JupyniumStartSync call.

It's minor because as soon as you make changes in vim it will be synced again.

[Question] Using custom renderer

From the documentation I take that Firefox is the only supported renderer because of Selenium:

Firefox (Other browsers are not supported due to their limitation with Selenium)

My question is, what Selenium features would a renderer need to support to be usable with Jupynium?
Basically, I don't want to use Firefox to display the notebook and would be completely fine with creating
a custom solution via WebKit (like this one: https://github.com/FelixKratz/JupyterApp-mac).

Automatically open homonymous file with `JupyniumLoadFromIpynbTab`

It would be very handy if we can automatically get Jupynium to open a new file called as the .ipynb file with the right .ju.* type (i.e. .ju.py for a python notebook,.ju.jl for a julia notebook and so on).
Maybe, this can be done only if the current buffer is empty/without name?

Use magic commands in LSP-friendly way

Jupytext support use magic commands like a comment, say,

# %time

2+3

would be regard as
image

But that does not work for jupynium
image

Could we have something similar to allow using magic commands without breaking LSP?

MD cells don't close at end of file

If you have an existing ipynb file that has a MD cell as the final cell, when you JupyniumLoadFromIpynbTab the ju file contains an MD block at the end that doesn't have a closing tag.

This leads to some errors because it's effectively ending the file on an open """:
image

Change notebook dir of auto started notebook server

I would really like to supply my own --NotebookApp.notebook_dir argument for the jupyter notebook server which gets auto started. The reason for this is that I eventually want to banish all .ipynb files to /tmp/, such that only the *.ju.py files are kept and the ipynb is generated from it every time I open the file.

Thank you for this awesome project! It truly is a dream come true!

Kernel interrupt and run all cells

Would love to see the following being implemented at some point:

  • Jupynium InterruptKernel
  • Jupynium RunAllCells

(Is there currently a way to run all cells without manually executing every cell in order?)

Notebook not auto-starting when opening .ju.py file (Windows)

I have my config setup to auto start and attach a server:

		auto_start_server = {
			enable = true,
			file_pattern = { "*.ju.*" },
		},
		auto_attach_to_server = {
			enable = true,
			file_pattern = { "*.ju.*" },
		},

However, when I open a *.ju.py file the server doesn't start automatically.

I have confirmed that manually starting/attaching with :JupyniumStartAndAttachToServer works OK

My config: https://github.com/sho-87/dotfiles/blob/master/nvim/lua/plugins/modules/jupynium.lua

Add support for ipdb

TIL there is a debugger in jupyter, namely, we can use

%debug

to enter most recent traceback, see https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-debug.

This feature is extremely useful for me, but currently I have to leave neovim and interact with ipdb command line in Jupyter. If there is a dap-like interface that can be opened in neovim, it would be a killer feature.

Normally, we may need to implement dap for ipykernel's pdb, but because jupynium runs through the browser, we only need to forward input from neovim and output from Jupyter.

This is a big request, but if you also find this feature useful, I am willing to do my best to provide help.

JupiniumStartAndAttachToServer doesn't open Jupyter in Firefox; Jupynium not found but is installed

The Bug
I apologise if I've made an obvious mistake here but I can't get Jupynium working and it looks like such a fantastic solution. When I run :JupiniumStartAndAttachToServer nothing happens; when I run :JupiniumStartAndAttachToServerInTerminal Jupynium is not found, yet I'm pretty sure I have all the dependencies. I am using Linux.

To Reproduce
Steps to reproduce the behavior:

  1. Install Jupynium with lazy.nvim:
return {
  "kiyoon/jupynium.nvim",
  build = "pip3 install --user .",
  ft = { "python" },
}

Loading on python files including .ju.py files works as expected

  1. Install jupyter-notebook, jupyper-nbclassic, firefox, geckodriver
sudo pacman -S jupyter-notebook jupyper-nbclassic firefox geckodriver
  1. open main.ju.py; run
:JupiniumStartAndAttachToServer
  1. nothing happens; :JupyniumStartSync not available

Expected behaviour
Expected Jupyter to open and :JupyniumStartSync to be an available option

Logs in /tmp/jupynium/logs/
/tmp/jupynium does not exist
:JupyniumStartAndAttachToServerInTerminal returns:

No module named 
jupynium

Output of jupynium --version

command not found: jupynium

Output of nvim --version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1696795921

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Untitled.ipynb artifacts

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)

Jupynium crashes if more than one tab at startup

Hi, thanks for this plugin! I had a small issue when running with some extensions as described below.

Describe the bug
If there is more than one tab in the browser window when jupynium starts, it hangs and crashes with a timeout error.
This is a bit of an edge case, but it happened to me in a firefox profile where new tab was managed by an extension (tridactyl). This opened a second tab automatically.

To Reproduce
Steps to reproduce the behavior:

  1. Launch Jupynium with :JupyniumStartAndAttachToServerInTerminal
  2. Wait 10 seconds
  3. Jupynium terminal fails with message shown below
jupynium.cmds.jupynium:  520 - ERROR - Exception occurred
Traceback (most recent call last):
  File "/home/vandal/.local/lib/python3.10/site-packages/jupynium/cmds/jupynium.py", line 461, in main
    driver_wait.until(EC.number_of_windows_to_be(1))
  File "/usr/lib/python3.10/site-packages/selenium/webdriver/support/wait.py", line 95, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

jupynium.cmds.jupynium:  321 - INFO - Jupyter Notebook server (pid=29665) has been killed.

Expected behavior
I would expect either Jupynium works normally if there is more than one tab in the window it starts in, or the incompatibility to be documented somewhere. The simplest fix was of course to change the new tab to default in the profile used by jupynium, but I think Jupynium can be made more generic relatively simply (see "Additional context"). The latter option would enable more flexible workflows for users.

Output of jupynium --version

Jupynium v0.1.2.dev51+gb79a625

Output of nvim --version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Additional context
The lines of code involved are the following:

driver_wait = WebDriverWait(driver, 10)
driver_wait.until(EC.number_of_windows_to_be(1))

I tried replacing the EC.number_of_windows_to_be by a function that checks "greater than 1" instead of "equal to 1" and it seems to fix the issue. I can send a PR if you want.

No action on JupyniumStartAndAttachToServer and "Not an editor command JupyniumExecuteSelectedCells"

Describe the bug
A clear and concise description of what the bug is.

To Reproduce

For JupyniumStartAndAttachToServer command:

Just open a .ju.py file and use the command:

:JupyniumStartAndAttachToServer

Nothing happens.

for Not an editor command JupyniumExecuteSelectedCells" error message:

Steps to reproduce the behavior:

  1. Create a simple test.ju.py file
  2. Create a simple cell usin #%% separator
  3. Press space, x to execute the Cell

Expected behavior
Cell executed.

Logs in /tmp/jupynium/logs/

2024-02-15 17:58:15,677 - jupynium.cmds.jupynium:   93 - INFO - Using firefox profile: None
2024-02-15 17:58:17,337 - jupynium.cmds.jupynium:  397 - INFO - Writing Jupyter Notebook server log to: /tmp/tmpbuacinx0
2024-02-15 17:58:18,490 - jupynium.cmds.jupynium:  546 - INFO - No nvim attached. Waiting for nvim to attach. Run jupynium --nvim_listen_addr /tmp/example (use `:echo v:servername` of nvim)
2024-02-15 17:58:21,852 - jupynium.cmds.jupynium:  592 - INFO - Browser disconnected. Quitting Jupynium.
2024-02-15 17:58:21,859 - jupynium.cmds.jupynium:  608 - SUCCESS - Piecefully closed as the browser is closed.
2024-02-15 17:58:21,875 - jupynium.cmds.jupynium:  344 - INFO - Jupyter Notebook server (pid=1304524) has been killed.

Operation system: Linux Fedora 39

Write large binary in logs

Arch linux use memory as /tmp so I fount this as it result in memory leak in my end.

A typical logs looks like

image

Delete this line make the file size reduce to 900k from 30M. 30M is not a dealbreaker, but it can also goes to 8G and I cannot open it yet.

2023-09-14_20-19-13.log

Troubles to use jupynium from a remot machine

Hi,

Thanks for releasing jupynium,

I am trying to install jupynium for using it from a remote machine. Specifically, I would like to render the notebook from firefox in an interface machine (machine A) while running the kernel and nvim in a remote machine (machine B). To do so I am using the command-line usage of jupynium as suggested. While I can launch jupynium correctly (I see a jupynium widget in nvim saying that it is set and firefox opens a geckodriver window on my notebook dir), if I run :JupyniumStartSync it crashes due to window undefined in selenium (error messages paste below)

To Reproduce
Steps to reproduce the behavior:

  1. From machine A : ssh -X machine B
  2. Launch jupyter notebook from the same dir as *.ju.py files
  3. Run nvim file.ju.py and get nvim address with :echo v:servername
  4. Launch jupynium : jupynium --nvim_listen_addr /tmp/your_socket_path --notebook_URL notebook_URL where notebook_URL is http://machine_b_name:port_number/
  5. Run :JupyniumStartSync in nvim

Expected behavior
At step 4 jupynium should launch firefox as expected but at step 5 it will crash with the following error message:

jupynium.cmds.jupynium: 512 - ERROR - Uncaught exception occurred while processing events. Detaching nvim.
Traceback (most recent call last):
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 138, in _w3c_window
send_handle(window_name)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 134, in send_handle
self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h})
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
self.error_handler.check_response(response)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Unable to locate window: undefined
Stacktrace:
WebDriverError@chrome://marionette/content/error.js:175:5
NoSuchWindowError@chrome://marionette/content/error.js:409:5
GeckoDriver.prototype.switchToWindow@chrome://marionette/content/driver.js:1602:11
despatch@chrome://marionette/content/server.js:305:40
execute@chrome://marionette/content/server.js:275:16
onPacket/<@chrome://marionette/content/server.js:248:20
onPacket@chrome://marionette/content/server.js:249:9
_onJSONObjectReady/<@chrome://marionette/content/transport.js:501:20

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/cmds/jupynium.py", line 507, in main
status, rpcrequest_event = process_events(nvim_info, driver)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/events_control.py", line 205, in process_events
status, request_event = process_request_event(nvim_info, driver, event)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/events_control.py", line 429, in process_request_event
start_sync_with_filename(
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/jupynium/events_control.py", line 236, in start_sync_with_filename
driver.switch_to.window(nvim_info.home_window)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 130, in window
self._w3c_window(window_name)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 144, in _w3c_window
send_handle(handle)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/switch_to.py", line 134, in send_handle
self._driver.execute(Command.SWITCH_TO_WINDOW, {"handle": h})
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
self.error_handler.check_response(response)
File "/sqpc/hpc/sp_auction_np/clautrim/public/environments/venv_jupynium/lib64/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: Unable to locate window: undefined
Stacktrace:
WebDriverError@chrome://marionette/content/error.js:175:5
NoSuchWindowError@chrome://marionette/content/error.js:409:5
GeckoDriver.prototype.switchToWindow@chrome://marionette/content/driver.js:1602:11
despatch@chrome://marionette/content/server.js:305:40
execute@chrome://marionette/content/server.js:275:16
onPacket/<@chrome://marionette/content/server.js:248:20
onPacket@chrome://marionette/content/server.js:249:9
_onJSONObjectReady/<@chrome://marionette/content/transport.js:501:20

Output of jupynium --version

Jupynium v0.1.dev1+gaaa0e59

Output of nvim --version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by girolims@ldzls998i

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Despite my efforts to fix this, I couldn't find what I did wrong here, any help would be greatly appreciated thanks!

Standardizing code and markdown separators

Would it be possible to add both opening and closing separators for code cells, especially when converting from an existing ipynb? This is what's currently done for markdown cells because docstrings require the closing tag, but there are a few benefits for enforcing this format for code cells too when converting:

  1. it simplifies visual scanning in some ways because it fully encapsulates a code block - you know that everything between 2 separators belongs to the same chunk of code
  2. if you want to have 2 code blocks in a row, you currently need to separate them with a # %%, which means the separator in that case is functioning as both a block end and block start indicator
  3. it will make some future functionality easier to implement (whether in the core plugin, or defined by the user via keybinds). I was trying to add some keybinds to add new cells above/below the current, or to move cells, or to switch 2 cell locations, or to toggle between cell types (eg code -> markdown). it worked, but was difficult to reason about because of (2). with the new format, a new cell above will always be inserted before a start separator, new cell below will always be below an end separator, toggling cell type will always change 2 lines etc. this will simplify keybinding things like "new cell below" without needing to check for things like file-end, or the presence of a next separator
  4. a stricter format would eliminate niche situations like "if there is one or more cells, it works as a notebook mode. Contents before the first cell are ignored, so use it as a heading", where markdown sometimes requires separators, and sometimes doesn't, depending on location and existence of other types of cells

so the proposed standard would be something like:

> myfile.ju.py

"""%%
Title
%%"""

# %%
code block 1
# <new closing tag>

# %%
code block 2
# <new closing tag>

The downside of course is that ju files become a bit more difficult to read as there will be more separators, but I think shortsighted mode helps a lot with this. And it would be fairly simple to add bg highlights to separator lines to indicate the cells (like the way jukit does it)

JupyniumStartAndAttachToServer didn't open a browser

Simply run JupyniumStartAndAttachToServer for a *.ju.py file do nothing for me(no notebook open) and say "[Jupynium]: Jupynium sucessfully attached and in
itialised. Run :JupyniumStartSync"

then run :JupyniumStartSync gives me

Jupynium: RPC channel closed. Stop sending all n
otifications.
[Jupynium]: Cancelling sync.

how to debug from there?

Allow setting Firefox profile path so jupynium can remember passwd or token

I have play jupynium for a while and it works like a charm, however I found it's annoying to enter token(passwd) everytime. A simple but less elegant way is to make selenium refer to default profile:

def webdriver_firefox():
    profile = webdriver.FirefoxProfile("/home/username/.mozilla/firefox/7kl5jw0d.default-release/")
    profile.set_preference("browser.link.open_newwindow", 3)
    profile.set_preference("browser.link.open_newwindow.restriction", 0)
    # profile.setAlwaysLoadNoFocusLib(True);
    return webdriver.Firefox(profile, service_log_path=os.path.devnull)

the directory can be found by https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data#w_how-do-i-find-my-profile. ("~" refer to home seems not work for me btw).

This is good enough for me, but I'm sure you have better ideas :)

Can't install Jupynium - error with dependencies

Describe the bug
I can't install the jupynium with python3 and showing an error with dependencies. I tried installing it from nvim and from the terminal itself but it didn't install.

To Reproduce
Steps to reproduce the behavior:

  1. just followed the instruction to install via lazy.nvim
  2. once trying to install the issue appear.

Screen Shot 2023-01-12 at 9 39 31 PM

Screen Shot 2023-01-12 at 9 39 43 PM

different way to reproduce:

  1. just do in the terminal: pip3 install --user jupynium
  2. the issue will immediatley appear.

Screen Shot 2023-01-12 at 9 39 11 PM

Expected behavior
to be installed correctly

The output

Collecting jupynium
Using cached jupynium-0.1.0.tar.gz (28 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

Γ— Getting requirements to build wheel did not run successfully.
β”‚ exit code: 1
╰─> [17 lines of output]
Error in sitecustomize; set PYTHONVERBOSE for traceback:
AssertionError:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 351, in
main()
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "/usr/local/lib/python3.10/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "/usr/local/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/setuptools/build_meta.py", line 338, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "/usr/local/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/setuptools/build_meta.py", line 320, in _get_build_requires
self.run_setup()
File "/usr/local/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/setuptools/build_meta.py", line 335, in run_setup
exec(code, locals())
File "", line 2, in
ModuleNotFoundError: No module named 'versioneer'
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

Γ— Getting requirements to build wheel did not run successfully.
β”‚ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Output of jupynium --version

Paste the output here

Output of nvim --version

NVIM v0.8.2

Additional context
OS: MacOS 12.6
Python: Python 3.10.9
I don't use conda or miniconda

Yanking and Pasting into *.ju.py file creates duplicated lines

Describe the bug
When pasting text that's in your clipboard/register(s)/etc, the notebook open in the browser seems to post a number of duplicate lines which then causes a de-sync between the file open in neovim and the text in the notebook. For example, I yanked the text "pd.read_sql(sql, CONNECTION_STRING)" from another neovim buffer I had open (a normal .py file), and then pasted it in my .ju.py file, and then the notebook open in the firefox window shows a number of duplicates, or to be exact:

pd.read_sql(sql, CONNECTION_STRING)
pd.read_sql(sql, CONNECTION_STRING)
pd.read_sql(sql, CONNECTION_STRING)
pd.read_sql(sql, CONNECTION_STRING)
pd.read_sql(sql, CONNECTION_STRING)

This issue also pops up when you have something like autopairs that completes closing quotes (e.g.
typing """ in python and it automatically generates the closing """. It seems to always result in 4 additional copies, as far as I can tell.

To Reproduce
Steps to reproduce the behavior:

  1. Start up jupynium as described in readme
  2. Have another buffer/tab/etc open containing other code
  3. Yank some text/code
  4. Paste it in your .ju.py file
  5. Results in duplicate lines in notebook

Expected behavior
Expected behavior is to have pasted text in neovim buffer to result in same exact text in notebook

Output when using jupynium command
If you launch Jupynium server using the command line program, it gives you more helpful logs.

N/A (using neovim plugin rather than command line tool)

Output of jupynium --version

N/A (using neovim plugin rather than command line tool)

Output of nvim --version

NVIM v0.9.1
Build type: Release
LuaJIT 2.1.0-beta3

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Additional context
N/A

:JupyniumStartSynch hangs and then closes notebook window

Describe the bug
Neovim Hangs on :JupyniumStartSynch (with command selection area open) and then eventually closes the firefox notebook window.

Priort to that: It successfully opens a Firefox window with Jupiter notebook with :JupyniumStartSyncAndAttachToServer command. :J...StartSynch also does open up one of the files -- it just is never able to do anything with it.

The hang and close happens regardless of input from the user. (I can not touch board nor mouse or switch windows -- either way the same result.)

Final output in nvim command line:

Jupynium: RPC channel closed.  Stop sending all notifications.
[Jupynium]: Cancelling sync...

Instal versions:
GeckoDriver: 0.33.0
NVIM: 0.9.1
Jupyter Notebook: 6.5.4
Python: 3.11.3
macOS: 13.4

To Reproduce
Run the exact descriptions in the QuickStart section

Expected behavior
A clear and concise description of what you expected to happen.

Output when using jupynium command
Unable to open jupynium via command line, despite it being an installed Python module
jupynium 0.1.dev1+fg5faa4b

(SideNote: this plugin sounds amazing. It would solve a huge gap -- making notebooks civilized coding environments.)

Respect kernel from Jupyter/Jupytext kernelspec when specified

Is your feature request related to a problem? Please describe.
When an ipynb is converted with Jupytext, the kernelspec is kept in the header (see below for example). That way, if a kernel is set (for e.g. manualy in the jupytext header, or with a tool like Juypterlab), the info is kept in the Python file. It would be nice if:

  1. When there is a jupytext header, there kernel could be automatically selected based on the kernelspec -> name info.
  2. There was a similar feature (header with metadata) in Jupynium files.

Describe alternatives you've considered
For now, I'm using a mapping to :JupyniumKernelSelect, which works well. The main advantage of reading metadata would be to avoid re-setting the kernel time I open the notebook.

Example Jupytext header:

# ---
# jupyter:
#   jupytext:
#     cell_metadata_filter: -all
#     formats: ipynb,py:percent
#     text_representation:
#       extension: .py
#       format_name: percent
#       format_version: '1.3'
#       jupytext_version: 1.14.5
#   kernelspec:
#     display_name: testjup
#     language: python
#     name: testjup
# ---

I think this is the type of thing I would be able to work on at some point and submit a PR, if you want. It mostly means reading extra info from an input file, and the Jupyter API commands should be the same as when selecting a kernel manually, right?

Thank you!

JupyniumLoadFromIpynbTab hangs for large ipynb project

The function JupyniumLoadFromIpynbTab hangs when I try to use it with a large ipynb file (which I am not able to share), possibly an infinite loop is created. I am not entirely sure why that happens for larger files but not small test files I have created.

On debian 12 ain't working

When I run :JupyniumStartAndAttachToServer from nvim 0.10 no tab open just, says it's attached and synced and prompts me to use

jupyniumNotWork0

Though then using the command JupyniumStartSync command, says cancelling sync and does nothing.

jupynium1

Tried many ways to get jupynium working, but couldn't.

I believe all requirements are installed.

Output of jupynium --version

Jupynium v0.2.0

Output of nvim --version

NVIM v0.10.0-dev-766+gef44e5972
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Run "nvim -V1 -v" for more info

Output of :JupyniumStartAndAttachToServerInTerminal

jupynium.pynvim_helpers: 11 - INFO - nvim addr: /run/user/1000/nvim.25647.0
jupynium.pynvim_helpers: 30 - INFO - nvim attached
jupynium.pynvim_helpers: 34 - INFO - Initialising..
jupynium.pynvim_helpers: 35 - INFO - Communicating with channel_id 5
jupynium.cmds.jupynium: 90 - INFO - Using firefox profile: None
jupynium.cmds.jupynium: 539 - ERROR - Exception occurred
Traceback (most recent call last):
File "/home/aokis/darbas/virtualibook/lib/python3.11/site-packages/jupynium/cmds/jupynium.py", line
452, in main
with webdriver_firefox(
^^^^^^^^^^^^^^^^^^
File "/home/aokis/darbas/virtualibook/lib/python3.11/site-packages/jupynium/cmds/jupynium.py", line
96, in webdriver_firefox
return webdriver.Firefox(profile, service_log_path=os.path.devnull)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: WebDriver.init() got an unexpected keyword argument 'service_log_path'

[Process exited 0]


Enable default kernel so no needs to use *.ju.* file

I think it would be great to give one the opportunity to use jupynium without using a suffix like .ju. (for lazy users). I started working on it (as I am using remote-local, I could only work on jupynium as a python package rather than an installed nvim plugin, but I don't think it is relevant here).

As this default kernel would be user dependent I think it should be defined in ~/.jupynium/preferences.yml with a line like:
default_kernel: 'python3'
Thus multiple users of a single venv could define different default kernels. Then, we would override the found kernel_name (when processing start_sync) by reading this yaml file (if the default_kernel is defined). The advantage of such solution would be to reuse this yaml file for other customization (like replacing the percent syntax by anything).

I've implemented a potential solution but I struggle a bit on the following:
If I launch jupynium with a nvim editing test.txt it works fine, but if I close it and re-open another file, this file is ignored unless it follows the ju. syntax. (I can see, in the first case, that the file is not added to the queue as https://github.com/kiyoon/jupynium.nvim/blob/master/src/jupynium/cmds/jupynium.py#L556 is consistently empty). I couldn't find why this happens though.

Let me know if this solution would be acceptable for you and if you know what is blocking me above so I can raise a PR for it,
Thanks!

Selenium Timeout Exception on NixOS

Describe the bug
TimeOutException after severeal seconds when running jupynium. After attaching the Server firefox is successfully opened, and selenium red bar is active. I think this could be an issue because of running it on NixOS and its filesystem.

To Reproduce
Steps to reproduce the behavior:

  1. Create conda environment
  2. Install jupynium and dependencies with pip (using requirments.txt)
  3. Run nvim with listen and run jupynium according to README instructions
  4. AttachToServer
  5. See error

Expected behavior
Able to use plugin...

Output when using jupynium command

timeout

Output of jupynium --version

Jupynium v0.1.1.dev44+g26e79c8

Output of nvim --version

NVIM v0.8.1

Additional context
Copied selenium and pkgbuild libraries from python3.10 conda environment folder into python3.9 system folder. Otherwise the following error message:
image

When importing selenium in conda environment, it works fine:
image

Make Jupynium compatible with non-jupynium (`*.ju.*`) files

Is your feature request related to a problem? Please describe.
It would be nice to be able to use jupynium.nvim with "regular" scripts (non-jupynium files e.g. somefile.py), such as py:precent scripts from jupytext. These are relatively common and used across many editors, so supporting them would help make the plugin compatible with more projects.

From what I understand, this is almost supported. I was able to start the server, attach and sync. However, highlighting and keymaps are not available. The py:percent format is also already supported if the file is a *.ju.* file.

Describe the solution you'd like
I think making the pattern, which is currently hardcoded for the keymap and highlighting autocmmand, configurable would solve this. Maybe there could be a main "pattern" option, and have the current command-specific file_pattern to override?

If the above option (or something else that enables this feature) would be acceptable, I'd be happy to work on a PR.

Describe alternatives you've considered
An alternative would be to automatically rename the file with .ju.{py,r,etc} suffix when opening it, but it would become cumbersome to specify when this should or should not be done. Another option is to convert to ipynb with jupytext, and then to ju.* with ipynb2jupy, but this seems like a lot of back-and-forth between file formats.

Use Firefox Developer Edition on MacOS

Describe the bug
jupynium always launches jupyter in Firefox.app, even though the default browser is set to Firefox Developer Edition.app.

Output of jupynium --version

Jupynium v0.2.2.dev10+gc6fdf2f

Output of nvim --version

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1700008891

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.4/share/nvim"

Run :checkhealth for more info

Default keymaps are not removed (Windows)

I have turned default keymaps off in my config and have setup a few new binds:

use_default_keybindings = false,
textobjects = {
    use_default_keybindings = false,
},

I can see my new custom binds OK, but the default maps still show up in my which-key and seems like they are still being set? Presumably this has something to do with me not having any replacement binds for the default <space>x, for example

image

My config:

Start from ipynb and start sync errors out

This is the error I am receiving:
Screenshot 2023-01-23 at 15 28 16

The file is populated anyways, so the loading seems to work. The document is not synced and I have to manually invoke start sync, then another tab opens and this one is synced.

Invalid Host header

Describe the bug
Can't run jupynium server. Get error:

jupynium.cmds.jupynium:   93 - INFO - Using firefox profile: None
jupynium.cmds.jupynium:  595 - ERROR - Exception occurred
Traceback (most recent call last):
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/jupynium/cmds/jupynium.py", line 498, in main
    with webdriver_firefox(
         ^^^^^^^^^^^^^^^^^^
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/jupynium/cmds/jupynium.py", line 102, in webdriver_firefox
    return webdriver.Firefox(options=options, service=service)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.py", line 69, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
    self.start_session(capabilities)
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/mnt/1/Documents/labs/4.2/neural_network/venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Invalid Host header localhost:35837

To Reproduce
> jupynium

Expected behavior
Server runs without exception

Output of jupynium --version

Jupynium v0.2.3.dev1+g71c3c15

Output of nvim --version

NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1702233742

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Additional context
Jupynium runs from venv

Tridactyl

Maybe this is a silly request and it's possible to do it already using something related to Firefox, but it would be very cool to be able to open the Firefox+Jupyter instance with some extensions.
In particular, I'm thinking of Tridactyl, but I think other people would probably be interested in other extensions.

Change kernel

  1. Add a command :JupyniumSelectKernel which will list all kernels you can switch to.
  • default cursor (selection) to the current kernel
  • Done in #38
  1. When starting sync by creating a new ipynb file, automatically choose the appropriate kernel.
  • It will only work if the neovim and Jupynium runs on the same computer.
  • Don't change kernel and use the default ipython3 if it can't find the match.
  • Respect filetype.
  • Choose based on conda_env_path if conda environment is activated
  • Done in #39
  1. Add a command :JupyniumRestartKernel

Useful javascript functions:

  • Jupyter.kernelselector.kernelspecs
  • Jupyter.notebook.kernel.name
  • Jupyter.kernelselector.set_kernel('conda-env-jupyter-r')
  • Jupyter.notebook.kernel.restart()
  • Jupyter.kernelselector.kernelspecs['conda-env-jupynium-py'].spec.language

Keymaps not set properly if plugin is lazy loaded

Default keymaps are not applied when plugin is lazy loaded like this

return {
    "kiyoon/jupynium.nvim",
    build = "pip3 install --user .",
    event = "BufWinEnter *.ju.py",
    config = function()
       require("jupynium").setup({})
   end
}

I tried adding this bit of logic to the plugin setup function but it doesn't work because autocommand-patterns are not the same as lua patterns.

I also tried using glob2regpat but that didn't quite work either.

So I guess the question boils down to how do we check if a filename matches an autocommand-pattern. I haven't been able to figure that out.

local filename = vim.fn.expand "%"
local buf_id = vim.api.nvim_get_current_buf()
for _, pattern in ipairs(options.opts.jupynium_file_pattern) do
  if filename:match(pattern) then
    if options.opts.use_default_keybindings then
      M.set_default_keymaps(buf_id)
    end
    if options.opts.textobjects.use_default_keybindings then
      textobj.set_default_keymaps(buf_id)
    end
    break
  end
end

Jupyter Notebook 7 compatibility (discussion)

Describe the bug
This plugin is not compatible with Jupyter Notebook 7 (as it follows the Jupyter Lab design).

To Reproduce
pip install notebook==7.0.0.a18

Output of jupynium --version

0.2.0

Additional Context
Currently, this plugin doesn't support Jupyter Lab. The reason is that Jupyter Lab doesn't provide a front-end API to interact using Selenium. A possible way may be writing a Jupyter Lab extension, and communicate with the extension, but it will be much more complicated to set up Jupynium that way..

Problems:

  • Writing a Jupynium extension requires one extra version to match. It requires Jupynium plugin version and the Jupyter Lab extension version to exactly match. So whenever you update Jupynium, you'll be required to update all of your server's Jupyter Lab extension.
  • It will be one more configuration required. Instead of communicating with the browser, now you'll need to communicate with the Jupyter Lab extension, then the extension needs to listen to a socket.
  • It will be harder to maintain. The contributors need understanding in all lua, python, typescript and Neovim / Jupyter Lab extension development experiences.

I may be wrong here, but if anyone can find a Jupyter Lab front-end method without using an extension please let me know. You can try with Jupyter Notebook like this:

  1. Press F12 to open a developer console
  2. Write Jupyter.notebook. and see the APIs like setting text on cells etc.

(see https://stackoverflow.com/questions/51411871/where-is-a-docs-for-jupyter-front-end-extensions-javascript-api)

This is simply what I need, and it looks like the new Jupyter Lab and Jupyter Notebook 7 doesn't support this.

Suggested Solution
Luckily, it looks like we can still use nbclassic (pip install nbclassic) and it will still serve the classic notebook UI. We will need to change the default address to localhost:8888/nbclassic, or maybe Jupynium can detect if the server running is not compatible and fallback to the nbclassic URL. This and Notebook 6 are supported for 2 more years.

Native Windows support without WSL

The current implementation uses sysv_ipc package to communicate to already existing server to add more neovim instances.

For example, instead of opening another browser just because you have another neovim open, it can reuse the browser and open a new tab.

Task 1. To make the CLI compatible with Windows, we need to replace it with a cross-platform message queue, and file-based queue seems promising. persist-queue.

Task 2. To make the plugin compatible with Windows, the plugin should detect the shell when calling the python program.
It should detect the OS, and further detect if powershell or CMD is running. If Powershell is running, the current syntax should work the same, maybe. (& at the end of the command for forking)
If CMD is running it needs to replace the command.

Kernel fails to start, resulting in timeout

Describe the bug
On jupyter notebook 7.0.4, the kernel fails to start and jupynium times out. The issue seems to be related to the way jupyter command is started from jupinium using subprocess.Popen where only stdout is attached and not stderr.

To Reproduce
Steps to reproduce the behavior:

Open any .ju.py file, then run JupyniumStartAndAttachToServer followed by JupyniumStartSync.

Expected behavior
The JupyniumStartSync command hangs until timing out after 30s.

Logs in /tmp/jupynium/logs/
The tmp directory path can be different in a different OS.
Alternatively, run :JupyniumStartAndAttachToServerInTerminal to see the output directly in neovim.

2023-10-02 11:49:17,124 - jupynium.pynvim_helpers: 11 - INFO - nvim addr: /run/user/1000/nvim.1144391.0
2023-10-02 11:49:17,128 - jupynium.pynvim_helpers: 30 - INFO - nvim attached
2023-10-02 11:49:17,128 - jupynium.pynvim_helpers: 34 - INFO - Initialising..
2023-10-02 11:49:17,128 - jupynium.pynvim_helpers: 35 - INFO - Communicating with channel_id 11
2023-10-02 11:49:17,133 - jupynium.cmds.jupynium: 93 - INFO - Using firefox profile: None
2023-10-02 11:49:18,473 - jupynium.cmds.jupynium: 397 - INFO - Writing Jupyter Notebook server log to: /tmp/tmp
sjqwjfgy
2023-10-02 11:49:22,847 - jupynium.events_control: 197 - INFO - Event from nvim: ['request', 'start_sync', [1,
'', True, ['# %%', 'print("hello, world")', 'plt.plot([1, 2, 1])', '', '# %%', 'import plotly.express as px', 'p
x.scatter(y=[1, 2, 1])', '', '# %% [markdown]', '"""', 'Hello, this is my markdown', '"""', '', '# %%', "var =
'foo'"], 'python', None], <pynvim.msgpack_rpc.async_session.Response object at 0x7f282babced0>]
2023-10-02 11:49:53,929 - jupynium.selenium_helpers: 38 - ERROR - Timed out waiting for kernel to load
Traceback (most recent call last):
File "/home/joh/code/jupynium.nvim/src/jupynium/selenium_helpers.py", line 32, in wait_until_notebook_loaded
WebDriverWait(driver, timeout).until(
File "/home/joh/.local/lib/python3.11/site-packages/selenium/webdriver/support/wait.py", line 95, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

2023-10-02 11:49:54,415 - urllib3.connectionpool: 824 - WARNING - Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f282bac0490>: Failed to establish a new connection: [Errno 111] Connection refused')': /session/eb7514c4-c2ce-466c-a34c-8d749b2ee1c3/window

Output of jupynium --version

Jupynium v0.2.1

Output of nvim --version

NVIM v0.9.1

go to definition closes jupynium tab and stops syncing

In my setup, jupynium will automaticlly close tab when the sync file is not in current buffers. But this would be a little annoyed if I just leave the current file just to check some definition by vim.lsp.buf.definition.

Is this by design? Could I do something to workaround it or if there exist a better workflow?

High CPU Usage

It seems when ever Jupynium is running it has a fairly high cpu utilization. I.e. when I run a regular jupyter notebook I will rarely see the cpu utilization (at idle) go above 1%, with jupynium running the python3 process is at a constant ~50% utilization. This could be due to an aggressive polling, but I am not sure.

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.