added python debug session with venv search

This commit is contained in:
Oliver Hartmann 2022-08-09 14:17:01 +02:00
parent 14fd19bde6
commit 4a21802429

View File

@ -18,33 +18,48 @@ vim.keymap.set('n', '<S-F11>', ":lua require('dap').step_out()<CR>", opts)
-- detached = true; -- detached = true;
-- }; -- };
-- } -- }
-- dap.configurations.python = { local function getVenvSuffix()
-- { if vim.loop.os_uname().sysname == 'Linux' then
-- -- The first three options are required by nvim-dap return 'bin/python'
-- type = 'python'; -- the type here established the link to the adapter definition: `dap.adapters.python` elseif vim.loop.os_uname().sysname == 'Windows_NT' then
-- request = 'launch'; return 'Scripts/python.exe'
-- name = "Launch file"; end
-- end
-- -- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
-- function getPythonEnv()
-- program = "${file}"; -- This configuration will launch the current file if used.
-- pythonPath = function() local venv = os.getenv("VIRTUAL_ENV")
-- -- debugpy supports launching an application with a different interpreter then the one used to launch debugpy itself. if venv ~= nil then
-- -- The code below looks for a `venv` or `.venv` folder in the current directly and uses the python within. return string.format("%s\\bin\\python.exe",venv)
-- -- You could adapt this - to for example use the `VIRTUAL_ENV` environment variable. end
-- local venv = os.getenv("VIRTUAL_ENV")
-- return string.format("%s\\bin\\python.exe",venv) local cwd = vim.fn.getcwd()
-- -- local cwd = vim.fn.getcwd() if vim.fn.executable(cwd .. '/venv/' .. getVenvSuffix()) == 1 then
-- -- if vim.fn.executable(cwd .. '/venv/bin/python') == 1 then return cwd .. '/venv/' .. getVenvSuffix()
-- -- return cwd .. '/venv/bin/python' elseif vim.fn.executable(cwd .. '/.venv/' .. getVenvSuffix()) == 1 then
-- -- elseif vim.fn.executable(cwd .. '/.venv/bin/python') == 1 then return cwd .. '/.venv/' .. getVenvSuffix()
-- -- return cwd .. '/.venv/bin/python' else
-- -- else if vim.loop.os_uname().sysname == 'Linux' then
-- -- return '/usr/bin/python' return '/usr/bin/python'
-- -- end elseif vim.loop.os_uname().sysname == 'Windows_NT' then
-- end; return os.getenv('SCOOP') .. '/apps/python/current/python.exe'
-- }, end
-- } end
end
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 with venv";
-- Options below are for debugpy, see https://github.com/microsoft/debugpy/wiki/Debug-configuration-settings for supported options
program = "${file}"; -- This configuration will launch the current file if used.
pythonPath = getPythonEnv()
},
}
require('dap-python').setup('C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python') require('dap-python').setup('C:\\Users\\oli\\AppData\\Local\\nvim\\venv_debugpy\\Scripts\\python')
table.insert(require('dap').configurations.python, { table.insert(require('dap').configurations.python, {