Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lua/jupytext/commands.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
local M = {}

M.run_jupytext_command = function(input_file, options)
local cmd = "jupytext " .. input_file .. " "
local cmd = { "jupytext", input_file }
for option_name, option_value in pairs(options) do
if option_value ~= "" then
cmd = cmd .. option_name .. "=" .. option_value .. " "
local option = option_name .. "=" .. option_value
table.insert(cmd, option)
else
-- empty string value implies this options is just a flag
cmd = cmd .. option_name .. " "
table.insert(cmd, option_name)
end
end

Expand Down
9 changes: 4 additions & 5 deletions lua/jupytext/health.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
local M = {}

M.check = function()
vim.health.report_start "jupytext.nvim"
vim.fn.system "jupytext --version"

vim.health.start "jupytext.nvim"
vim.fn.system({ "jupytext", "--version" })
if vim.v.shell_error == 0 then
vim.health.report_ok "Jupytext is available"
vim.health.ok "Jupytext is available"
else
vim.health.report_error("Jupytext is not available", "Install jupytext via `pip install jupytext`")
vim.health.error("Jupytext is not available", "Install jupytext via `pip install jupytext`")
end
end

Expand Down
12 changes: 7 additions & 5 deletions lua/jupytext/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ local write_to_ipynb = function(event, output_extension)
jupytext_filename = vim.fn.resolve(vim.fn.expand(jupytext_filename))

vim.cmd.write({ jupytext_filename, bang = true })
commands.run_jupytext_command(vim.fn.shellescape(jupytext_filename), {

commands.run_jupytext_command(jupytext_filename, {
["--update"] = "",
["--to"] = "ipynb",
["--output"] = vim.fn.shellescape(ipynb_filename),
["--output"] = ipynb_filename,
})

local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_set_option_value("modified", false, { buf = buf })

Expand Down Expand Up @@ -68,7 +70,7 @@ end

local read_from_ipynb = function(ipynb_filename)
local metadata = utils.get_ipynb_metadata(ipynb_filename)
local ipynb_filename = vim.fn.resolve(vim.fn.expand(ipynb_filename))
ipynb_filename = vim.fn.resolve(vim.fn.expand(ipynb_filename))

-- Decide output extension and style
local custom_formatting, output_extension, to_extension_and_style = style_and_extension(metadata)
Expand All @@ -79,9 +81,9 @@ local read_from_ipynb = function(ipynb_filename)
local filename_exists = vim.fn.filereadable(ipynb_filename)

if filename_exists and not jupytext_file_exists then
commands.run_jupytext_command(vim.fn.shellescape(ipynb_filename), {
commands.run_jupytext_command(ipynb_filename, {
["--to"] = to_extension_and_style,
["--output"] = vim.fn.shellescape(jupytext_filename),
["--output"] = jupytext_filename,
})
end

Expand Down