mfussenegger / nvim-dap-python

An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.
GNU General Public License v3.0
492 stars 46 forks source link

Windows venv detection #115

Closed Balandino closed 8 months ago

Balandino commented 11 months ago

Hello,

I setup dap-python and hit a problem detecting my virtual environment in Windows. My setup is as follows:

require("dap-python").setup(vim.fn.getcwd() .. "\\Scripts\\" .. "python.exe")
table.insert(require("dap").configurations.python, {
    type = "python",
    request = "launch",
    program = "${file}",
    console = "integratedTerminal",
    name = "Launch file with autoReload",
    justMyCode = false,
    autoReload = {
        enable = true,
    },
})

require("dap-python").resolve_python = function()
    return vim.fn.getcwd() .. "\\Scripts\\" .. "python.exe"
end

However when I attempted to run dap it kept appending /bin/python to the debugger command. I swapped out the is_windows() command from dap-python.lua (line 45) from:

 local is_windows = function()
     return vim.loop.os_uname().sysname:find("Windows", 1, true) and true
 end

to the following:

local is_windows = function()
  return vim.fn.has("win32") == 1
end

and it worked perfectly, appending \Scripts\python as needed. Unsure if this is a bug in my setup or the the plugin itself so reporting here. When I ran the original code for is_windows() it seemed to just return nil.

Please let me know if you require. more information and I'll see what I can do.

mfussenegger commented 8 months ago

Could you share the output of :lua print(vim.loop.os_uname().sysname)?

Balandino commented 8 months ago

Hello,

Sorry for the delay in getting back to you. The output of that command is:

MINGW32_NT-10.0

My Neovim should just be the .msi for Windows downloaded from the official github,

mfussenegger commented 8 months ago

Thanks, I changed the logic with https://github.com/mfussenegger/nvim-dap-python/pull/120