local actions = require("vern.actions.python") local config = require("vern.configs.python") return function(bufnr, user_opts) local opts = vim.tbl_deep_extend("force", {}, config, user_opts or {}) vim.api.nvim_buf_create_user_command(bufnr, "Pythonrun", function() if actions.run then actions.run(opts) end end, { desc = "Run python project" }) vim.api.nvim_buf_create_user_command(bufnr, "Pythonpip", function(cmd_args) if actions.pip_install then actions.pip_install(opts, cmd_args) end end, { nargs = "*", desc = "Install python packages" }) for key, def in pairs(opts.keybinds or {}) do if type(def.action) == "function" then vim.keymap.set("n", key, function() def.action(opts) end, { buffer = bufnr, silent = true, desc = def.desc, }) end end local root = require("vern.utils").get_project_root() if root then local venv_dir = nil if vim.uv.fs_stat(root .. "/venv/bin/python") then venv_dir = root .. "/venv" elseif vim.uv.fs_stat(root .. "/.venv/bin/python") then venv_dir = root .. "/.venv" end if venv_dir then vim.env.VIRTUAL_ENV = venv_dir vim.env.PATH = venv_dir .. "/bin:" .. vim.env.PATH end end end