-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mypy does not work under a venv #662
Comments
If There's probably something else wrong. Maybe the Does it work if you source linters_venv/bin/active before starting nvim? |
It does not work even with the environment sourced before starting neovim. |
@rhusiev Can you post your relevant config? I have set up my nvim to use mypy from a virtual environment and it works as expected. This is essentially what I'm doing: local nvim_lint = require("lint")
local venv_dir = "path/to/my/venv" -- computed during startup
nvim_lint.linters.mypy.cmd = venv_dir .. "/bin/mypy"
-- args copied from https://github.com/mfussenegger/nvim-lint/blob/master/lua/lint/linters/mypy.lua
nvim_lint.linters.mypy.args = {
mypy_path,
"--show-column-numbers",
"--show-error-end",
"--hide-error-context",
"--no-color-output",
"--no-error-summary",
"--no-pretty",
"--python-executable",
venv_dir .. "/bin/python",
}
nvim_lint.linters_by_ft = {
python = { "mypy" },
} Note that I only do this because I'm too lazy to activate the environment. If you activate your environment setting |
@hbibel Here you are: local lint = require("lint")
local mypy = lint.linters.mypy
local mypy_path = vim.fn.expand("$HOME/.local/share/venvs/linters_venv/")
mypy.cmd = mypy_path .. "bin/mypy"
mypy.args = vim.list_extend(mypy.args, {
function()
local filename = vim.api.nvim_buf_get_name(0)
local root_dir
root_dir = lspconfig_util.find_git_ancestor(filename)
root_dir = root_dir
or lspconfig_util.root_pattern("setup.py", "pyproject.toml", "setup.cfg", "requirements.txt")(filename)
root_dir = root_dir or lspconfig_util.root_pattern("*.py")(filename)
local cache_dir = vim.fn.expand("$HOME/.cache/mypy/") .. root_dir
return "--cache-dir=" .. cache_dir .. " --python-executable=" .. mypy_path .. "bin/python"
end
})
...
lint.linters_by_ft = {
python = { "flake8", "mypy" },
...
} |
@rhusiev can you make two changes:
Something like this: mypy.args = vim.list_extend(mypy.args, {
"--cache-dir=" .. cache_dir,
"--python-executable=" .. mypy_path .. "bin/python",
}) Apart from that I think it should work. Also make sure you're not using a very old mypy version. Adding |
Even when I do it like this: local mypy = lint.linters.mypy
local mypy_path = vim.fn.expand("$HOME/.local/share/venvs/linters_venv/")
mypy.cmd = mypy_path .. "bin/mypy"
mypy.args = {
"--python-executable",
mypy_path .. "bin/python",
"--show-column-numbers",
"--show-error-end",
"--hide-error-codes",
"--hide-error-context",
"--no-color-output",
"--no-error-summary",
"--no-pretty",
} Without extending |
still a Lua noob here so thank you very much @hbibel's for the hint on how to amend same, I don't activate virtual environments, preferring to refer to the executables within I'm always using running I ended up removing all args, relying on local M = {
"mfussenegger/nvim-lint",
dependencies = {
"williamboman/mason.nvim",
},
}
M.config = function()
local lint = require("lint")
lint.linters.mypy.args = {}
lint.linters_by_ft = {
python = {
"mypy",
},
}
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
group = lint_augroup,
callback = function()
lint.try_lint()
end,
})
end
return M I think some default setting are very good to have, even if not for me, but considering that, for |
When I install
mypy
for my user (pip install --user mypy
), it is recognized by nvim-lint and works.However, when I use a custom environment for my linters (I create some
python -m venv linters_venv
, add it to bash, .profile and vim.env.PATH), nvim-lint no longer runsmypy
.I can run
mypy
in my terminal and using:!mypy
in neovim, but nvim-lint does not seem to see it. I also tried changing therequire('lint').linters.mypy.cmd
to the absolute path tomypy
, but nvim-lint still did not run it.The text was updated successfully, but these errors were encountered: