Files
vern-nvim/lua/vern/actions/python.lua
T
DarthMooMancer 4bcac5d09b REFACTOR: I spent all day on it but I am heavily refactoring the API and
organization because it was terrible before and hard to maintain. Now it
should be much easier and there is still of a design decisions to figure
out
2026-10-15 02:07:14 -04:00

43 lines
1.2 KiB
Lua

local M = {}
local utils = require("vern.utils")
M.default_target_file = "main.py"
--- Goal is to add providers for uv and venv so its available to more users
---@param opts? table Takes a table for the runtime
function M.run(opts)
opts = opts or {}
local root = utils.get_project_root() or "."
local project_name = vim.fs.basename(root)
local pattern = vim.tbl_get(
opts,
"templates",
"project",
"executable",
"target"
) or "src/%s/main.py"
local rel_path = pattern:find("%%s")
and string.format(pattern, project_name)
or pattern
local full_path = root .. "/" .. rel_path
utils.terminal({ "python3 " .. full_path }, opts)
end
---@param cmd_args? table Takes a table for the runtime
function M.pip_install(opts, cmd_args)
if cmd_args and cmd_args.args and cmd_args ~= "" then
utils.terminal({ "pip install " .. cmd_args.args })
return
end
vim.ui.input({ prompt = "Enter pip module: " }, function(pip_module)
if not pip_module or pip_module == "" then
vim.notify("Pip Cancelled", vim.log.levels.WARN)
return
end
utils.terminal({ "pip install " .. pip_module }, opts or {})
end)
end
return M