Closed peter-bowman-lantern closed 2 months ago
Think I figured out how to solve it:
Basically use this function:
get_venv_command = function(command)
if vim.env.VIRTUAL_ENV then
return vim.env.VIRTUAL_ENV .. "/bin/" .. command)
else
return command
end
end
somewhere in your config and then set
require('conform').setup({
formatters = {
{
black = {
command = get_venv_command("black"),
},
},
}
This works for anything where you want to use the venv command where its activated and the global one vim will default to when its not
Neovim version (nvim -v)
0.9.5
Operating system/version
MacOs 14.14
Add the debug logs
log_level = vim.log.levels.DEBUG
and pasted the log contents below.Log file
Log file: /Users/bowmanpete/.local/state/nvim/conform.log 14:13:11[DEBUG] black stderr: { "Traceback (most recent call last):", ' File "/Users/bowmanpete/.config/nvim/lua/lsp_servers/bin/black", line 5, in', " from black import patched_main", ' File "src/black/init.py", line 31, in ', "ModuleNotFoundError: No module named 'click'", "" }
14:13:11[INFO] Run isort on /Users/bowmanpete/...point.py
14:13:11[DEBUG] Run command: { "isort", "--stdout", "--filename", "/Users/.....point.py", "-" }
14:13:11[DEBUG] Run CWD: /Users/...data-etl-library
14:13:11[DEBUG] isort exited with code 0
14:13:11[ERROR] Formatter 'black' error: Traceback (most recent call last):
File "/Users/bowmanpete/.config/nvim/lua/lsp_servers/bin/black", line 5, in
from black import patched_main
File "src/black/init.py", line 31, in
ModuleNotFoundError: No module named 'click'
Config/nvim/lsp_servers is the path I've installed my mason packages to
Describe the bug
Basically the path black is looking for is the path set in where I've told it that my lap servers are installed via mason. However my virtual environment is somewhere else. upon setting up the command = "python -m black" in order for it to obey my virtual env it doesn't work
then my check health output
![image](https://github.com/stevearc/conform.nvim/assets/167885709/200df07b-7130-40c6-8e45-c34ca074c46f)
What is the severity of this bug?
breaking (some functionality is broken)
Steps To Reproduce
Expected Behavior
It formats the file
Minimal example file
No response
Minimal init.lua
Additional context
No response