-
I have tried everything I could find about setting my debugger in LazyVim to work for the last 10 days. I need community help NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info My checkhealth ===========================================
provider.python: require("provider.python.health").check()
Python 3 provider (optional) ~
- Using: g:python3_host_prog = "/Users/pwd/.virtualenvs/nvim/bin/python"
- Executable: /Users/pwd/.virtualenvs/nvim/bin/python
- Python version: 3.11.9
- pynvim version: 0.5.0
- OK Latest pynvim is installed.
Python virtualenv ~
- $VIRTUAL_ENV is set to: /Users/pwd/Codes/saa/.venv
- Python version: 3.12.2
- OK $VIRTUAL_ENV provides :!python. No matter what I have tried, I ended up with a Python crash when debugging. Testing works fine, but debugging has rob 4 days of my sleep :) and torment me with nightmares 馃馃き And my whole config and plugin are heredotfiles dap logs[ INFO ] 2024-06-17T09:38:54Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:754 ] "Telemetry" "ptvsd"
[ INFO ] 2024-06-17T09:38:54Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:754 ] "Telemetry" "debugpy"
[ WARN ] 2024-06-17T09:38:54Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = { {
host = "127.0.0.1",
internal = false,
port = 52532
} }
},
event = "debugpySockets",
seq = 3,
type = "event"
}
[ WARN ] 2024-06-17T09:38:54Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = { {
host = "127.0.0.1",
internal = false,
port = 52532
}, {
host = "127.0.0.1",
internal = true,
port = 52533
} }
},
event = "debugpySockets",
seq = 5,
type = "event"
}
[ WARN ] 2024-06-17T09:38:54Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = { {
host = "127.0.0.1",
internal = false,
port = 52532
}, {
host = "127.0.0.1",
internal = true,
port = 52534
}, {
host = "127.0.0.1",
internal = true,
port = 52533
} }
},
event = "debugpySockets",
seq = 6,
type = "event"
}
[ WARN ] 2024-06-17T09:38:55Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = { {
host = "127.0.0.1",
internal = false,
port = 52532
}, {
host = "127.0.0.1",
internal = true,
port = 52533
} }
},
event = "debugpySockets",
seq = 8,
type = "event"
}
[ WARN ] 2024-06-17T09:38:56Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = { {
host = "127.0.0.1",
internal = false,
port = 52532
} }
},
event = "debugpySockets",
seq = 18,
type = "event"
}
[ WARN ] 2024-06-17T09:38:56Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = {}
},
event = "debugpySockets",
seq = 19,
type = "event"
}
[ WARN ] 2024-06-17T09:38:56Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1016 ] "No event handler for " {
body = {
sockets = {}
},
event = "debugpySockets",
seq = 20,
type = "event"
}
[ ERROR ] 2024-06-17T09:38:57Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1466 ] "stderr" {
args = { "-m", "debugpy.adapter" },
command = "/Users/pwd/.local/share/nvim/mason/packages/debugpy//venv/bin/python",
enrich_config = <function 1>,
options = {
source_filetype = "python"
},
type = "executable"
} "Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedReader name='<stdin>'> at interpreter shutdown, possibly due to daemon threads\nPython runtime state: finalizing (tstate=0x0000000101c59068)\n\nCurrent thread 0x0000000203430c00 (most recent call first):\n <no Python frame>\n"
[ INFO ] 2024-06-17T09:38:57Z+0200 ] .../pwd/.local/share/nvim/lazy/nvim-dap/lua/dap/session.lua:1439 ] "Process closed" 44747
Things, I have tried:
lua << EOF
local dap = require('dap')
dap.adapters.python = {
type = 'executable';
command = os.getenv("VIRTUAL_ENV") .. "/bin/python";
args = { '-m', 'debugpy.adapter' };
}
dap.configurations.python = {
{
-- The first three options are required by nvim-dap
type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python`
request = 'launch';
name = "Launch file";
cwd = os.getenv("HOME") .. "/Codes/saa/"; --python is executed from this directory
program = "${file}"; -- This configuration will launch the current file if used.
pythonPath = function()
-- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself.
-- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within.
-- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable.
local cwd = vim.fn.getcwd()
if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then
return cwd .. '/venv/bin/python'
elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then
return cwd .. '/.venv/bin/python'
else
return os.getenv("HOME") .. '/.virtualenvs/nvim/bin/python'
end
end;
},
}
EOF
example: return {
{
"mfussenegger/nvim-dap",
config = function()
local dap = require("dap")
-- Set up the Python adapter and configuration for nvim-dap
dap.adapters.python = function(cb, config)
if config.request == "attach" then
local port = (config.connect or config).port
cb({
type = "server",
port = assert(port, "`connect.port` is required for a python `attach` configuration"),
host = (config.connect or config).host or "127.0.0.1",
})
else
cb({
type = "executable",
command = "~/.virtualenvs/debugpy/bin/python",
args = { "-m", "debugpy.adapter" },
})
end
end
dap.configurations.python = {
{
type = "python",
request = "launch",
name = "FastAPI",
module = "uvicorn",
args = { "main:app", "-h", "0.0.0.0", "-p", "8002" },
env = function()
local variables = {
PYTHONPATH = "/Users/pwd/Codes/makelele/src",
}
for k, v in pairs(vim.fn.environ()) do
table.insert(variables, string.format("%s=%s", k, v))
end
return variables
end,
subProcess = false,
},
{
type = "python",
request = "launch",
name = "Python File",
program = "${file}",
console = "internalConsole",
pythonPath = function(adapter)
return "/Users/pwd/Codes/saa/.venv/bin/python"
end,
},
}
end,
},
} also another settingsreturn {
'mfussenegger/nvim-dap-python',
dependencies = {'mfussenegger/nvim-dap'},
config = function()
local dap = require('dap')
local dap_python = require('dap-python')
-- Retrieve the home directory and construct the debugpy path
local debug_path = vim.loop.os_homedir() .. '/.virtualenvs/debugpy/bin/python'
-- Function to get the current Python path
local function get_python_path()
-- Check if VIRTUAL_ENV is set
local venv_path = os.getenv('VIRTUAL_ENV')
if venv_path then
return venv_path .. '/bin/python'
end
-- Check for a .venv directory
local cwd = vim.fn.getcwd()
local venv_python = cwd .. '/.venv/bin/python'
if vim.fn.executable(venv_python) == 1 then
return venv_python
end
-- Fall back to system Python
return vim.fn.exepath('python3') or vim.fn.exepath('python') or debug_path
end
-- Determine the appropriate Python path
local python_path = get_python_path()
-- Setup dap-python with the debugpy path
dap_python.setup(debug_path)
-- Ensure the `python` adapter is available
dap.adapters.python = {
type = 'executable',
command = debug_path,
args = { '-m', 'debugpy.adapter' },
}
-- Example configuration for a Python file
dap.configurations.python = {
{
type = 'python',
request = 'launch',
name = "Launch file",
program = "${file}",
pythonPath = function()
return python_path
end,
},
}
end
}
-- Other plugins
} |
Beta Was this translation helpful? Give feedback.
Answered by
Proteusiq
Jun 18, 2024
Replies: 1 comment
-
solved 馃槃 I just need df return {
"mfussenegger/nvim-dap-python",
keys = {
{
mode = "n",
"<leader>df",
function()
require("dap-python").test_method()
end,
},
},
config = function()
require("dap-python").setup(vim.g.python_host_prog )
require("dap-python").test_runner = "pytest"
end,
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Proteusiq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solved 馃槃 I just need df