Files
vern-nvim/lua/vern-nvim/actions/python.lua
T
DarthMooMancer 5eaa7d10a7 refactor: realized I was heavily unoptimized.
Each language had the same boilerplate code to create new projects and
new files with minor differences between each language making them
difficult to edit and navigate.
2026-10-26 14:13:33 -04:00

46 lines
1.5 KiB
Lua

local M = {}
local utils = require("vern-nvim.utils")
---@param root string
M.create_project = function(root)
vim.fn.system("python3 -m venv " .. root .. "/venv")
end
M.create_file = function() end
---@param opts VernPythonConfig Takes a table for the runtime
function M.run(opts)
opts = opts or {}
local root = utils.proj_root() or "."
local pname = vim.fs.basename(root)
local bin = opts.python.templates.project.primary
local exe = vim.fs.joinpath(bin.path, bin.name) or "src/{project_name}/main.py"
local exe_path = utils.resolve_path(exe, opts.python.dirs, { project_name = pname })
local full_path = vim.fs.joinpath(vim.fn.expand(root), exe_path)
utils.term({ "python3 " .. full_path }, opts.terminal or {}, false)
end
function M.pip_install()
vim.ui.input({ prompt = "Enter pip module: " }, function(mod)
mod = mod and vim.trim(mod)
if not mod or mod == "" then
vim.notify("Pip Cancelled", vim.log.levels.WARN)
return
end
vim.notify("Installing " .. mod, vim.log.levels.INFO)
vim.system({ "pip", "install", mod }, { text = true }, function(obj)
vim.schedule(function()
if obj.code ~= 0 then
vim.notify("Pip failed: " .. obj.stderr, vim.log.levels.WARN)
else
vim.notify("Pip installed " .. mod, vim.log.levels.INFO)
end
end)
end)
end)
end
return M