set up jupynium plugin, letting neovim synchronously manage a local jupyter kernel

This commit is contained in:
dpearre 2024-10-07 21:18:15 -07:00
parent 7d2b75c299
commit 785f62cc1f
1 changed files with 138 additions and 0 deletions

138
init.lua
View File

@ -319,6 +319,14 @@ require('lazy').setup({
} }
end, end,
}, },
{
'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
-- NOTE: Plugins can also be added by using a table, -- NOTE: Plugins can also be added by using a table,
-- with the first argument being the link and the following -- with the first argument being the link and the following
@ -1042,5 +1050,135 @@ require('lazy').setup({
}, },
}) })
require('jupynium').setup {
--- For Conda environment named "jupynium",
--- python_host = { 'conda', 'run', '--no-capture-output', '-n', 'jupynium', 'python' },
python_host = { 'conda', 'run', '--no-capture-output', '-n', 'datascience', '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' },
jupyter_command = { 'conda', 'run', '--no-capture-output', '-n', 'datascience', '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',
},
},
notify = {
ignore = {
-- "download_ipynb",
-- "error_download_ipynb",
-- "attach_and_init",
-- "error_close_main_page",
-- "notebook_closed",
},
},
}
-- 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.
-- The line beneath this is called `modeline`. See `:help modeline` -- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et