diff --git a/lua/bootstrap.lua b/lua/bootstrap.lua index dab27a9..57f651f 100644 --- a/lua/bootstrap.lua +++ b/lua/bootstrap.lua @@ -28,18 +28,18 @@ local utils = require("utils") local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then if utils.os_name == "Linux" then - utils.assert_any_available({ "curl", "wget", }) - utils.assert_available("unzip") - utils.assert_available("gzip") + utils.assert_any_installed({ "curl", "wget", }) + utils.assert_installed("unzip") + utils.assert_installed("gzip") elseif utils.os_name == "Windows_NT" then - utils.assert_any_available({ "pwsh", "powershell", }) - utils.assert_any_available({ "7z", "peazip", "arc", "wzzip", "rar", }) + utils.assert_any_installed({ "pwsh", "powershell", }) + utils.assert_any_installed({ "7z", "peazip", "arc", "wzzip", "rar", }) else error("OS not supported: " .. utils.os_name) end - utils.assert_available("git") - utils.assert_available("tar") + utils.assert_installed("git") + utils.assert_installed("tar") local resp = vim.system({ "git", diff --git a/lua/pytest.lua b/lua/pytest.lua index 7cb4746..035c238 100644 --- a/lua/pytest.lua +++ b/lua/pytest.lua @@ -22,10 +22,9 @@ local env_ok = false local dap = nil local function check_env() - utils.exec("Asdf") - utils.assert_available("python3") - utils.assert_python3_module("debugpy") - utils.assert_python3_module("pytest") + utils.assert_installed("python3") + utils.python3_module_installed("debugpy") + utils.python3_module_installed("pytest") env_ok = true end diff --git a/lua/utils.lua b/lua/utils.lua index 728039a..7c97915 100644 --- a/lua/utils.lua +++ b/lua/utils.lua @@ -21,16 +21,16 @@ M.os_name = vim.loop.os_uname().sysname --- Check that an executable is available --- @param exe string: Array to look for --- @return boolean -function M.is_available(exe) +function M.is_installed(exe) return vim.fn.executable(exe) == 1 end --- Check that at least one executable is available --- @param exes table: Array of exes --- @return boolean -function M.any_available(exes) +function M.any_installed(exes) for _, e in ipairs(exes) do - if M.is_available(e) then + if M.is_installed(e) then return true end end @@ -41,8 +41,8 @@ end --- Asserts that an executable is available --- Raises error if missing. --- @param exe string: Array to look for -function M.assert_available(exe) - if not M.is_available(exe) then +function M.assert_installed(exe) + if not M.is_installed(exe) then M.notify("Missing executable '" .. exe .. "'.") end end @@ -50,15 +50,15 @@ end --- Asserts that at least one executable is available --- Raises error if missing. --- @param exes table: Array of exes -function M.assert_any_available(exes) - if not M.any_available(exes) then +function M.assert_any_installed(exes) + if not M.any_installed(exes) then error("At least one of the following is required:\n" .. table.concat(exes, ", ")) end end --- Asserts that a python module is installed ---@param mod string: The python module to check -function M.assert_python3_module(mod) +function M.python3_module_installed(mod) local resp = vim.system({ "python3", "-m", "pip", "show", mod, }):wait() if not resp.code == 0 then error("Python3 module " .. mod .. " not installed:\n" .. resp.stdout .. "\n" .. resp.stderr)