nvim-dap-python icon indicating copy to clipboard operation
nvim-dap-python copied to clipboard

Not using correct pythonpath?

Open emilnewel opened this issue 1 year ago • 2 comments

For some reason DAP can't figure out the correct pythonpath in my project. I can set breakpoints, see the UI, step a bit into my code but then the debugger stop when I hit the following line

from bar.conf import conf

when i run <cmd>echo $PYTHONPATH I get src/foo:src/bar:src/baz.

venv is set correctly as I can import and use packages installed with pip.

Everything works correctly in Pycharm/VSCode but I wanted to try to move everything over to nvim and this is the only piece of the configuration I have left.

My project structure

.
├── README.md
├── pyproject.toml
├── pyrightconfig.json
└── src
    ├── bar
    │   └── bar
    ├── foo
    │   ├── README.md
    │   ├── manage.py
    │   ├── foo
    │   └── requirements.txt
    └── baz
        └── baz

Dap configuration for python

return {
	{
		"mfussenegger/nvim-dap-python",
		config = function()
			local dap_python = require("dap-python")
			dap_python.setup("/Users/emil/.pyenv/versions/nvim-dap/bin/python") -- created seperate venv for debugpy
			dap_python.test_runner = "pytest"

			vim.keymap.set("n", "<leader>dn", dap_python.test_method, {})
			vim.keymap.set("n", "<leader>df", dap_python.test_class, {})
			vim.keymap.set("v", "<leader>ds", dap_python.debug_selection, {})
		end,
	},
	{
		"mfussenegger/nvim-dap",
		dependencies = { "rcarriga/nvim-dap-ui", "nvim-neotest/nvim-nio" },
		config = function()
			local dap, dapui = require("dap"), require("dapui")
			dapui.setup()
			dap.listeners.before.attach.dapui_config = function()
				dapui.open()
			end
			dap.listeners.before.launch.dapui_config = function()
				dapui.open()
			end
			dap.listeners.before.event_terminated.dapui_config = function()
				dapui.close()
			end
			dap.listeners.before.event_exited.dapui_config = function()
				dapui.close()
			end

			dap.configurations.python = {
				{
					name = "Python: Django",
					type = "python",
					request = "launch",
					program = "${workspaceFolder}/src/foo/manage.py",
					args = {
						"runserver",
					},
					django = true,
					justMyCode = true,
					purpose = {
						"debug-test",
					},
				},
			}
			vim.keymap.set("n", "<leader>b", dap.toggle_breakpoint, {})
			vim.keymap.set("n", "<F5>", dap.continue, {})
			vim.keymap.set("n", "<F10>", dap.step_over, {})
			vim.keymap.set("n", "<F11>", dap.step_into, {})
			vim.keymap.set("n", "<F12>", dap.step_out, {})
		end,
	},
}

emilnewel avatar Jun 25 '24 09:06 emilnewel