From ae210727129afd63d315b5a6a5445c882337b04c Mon Sep 17 00:00:00 2001 From: Illia Denysenko <42647349+juliancoffee@users.noreply.github.com> Date: Wed, 28 May 2025 18:16:29 +0300 Subject: [PATCH] feat: uv python detection (#98) (#98) --- lua/neotest-python/base.lua | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lua/neotest-python/base.lua b/lua/neotest-python/base.lua index 90cd6da..90671a2 100644 --- a/lua/neotest-python/base.lua +++ b/lua/neotest-python/base.lua @@ -72,6 +72,18 @@ function M.get_python_command(root) end end + if lib.files.exists("uv.lock") then + local success, exit_code, data = pcall( + lib.process.run, + { "uv", "run", "python", "-c", "import sys; print(sys.executable)" }, + { stdout = true } + ) + if success and exit_code == 0 then + python_command_mem[root] = { Path:new(data).filename } + return python_command_mem[root] + end + end + -- Fallback to system Python. python_command_mem[root] = { nio.fn.exepath("python3") or nio.fn.exepath("python") or "python", @@ -110,7 +122,7 @@ M.treesitter_queries = [[ ]] M.get_root = - lib.files.match_root_pattern("pyproject.toml", "setup.cfg", "mypy.ini", "pytest.ini", "setup.py") + lib.files.match_root_pattern("pyproject.toml", "setup.cfg", "mypy.ini", "pytest.ini", "setup.py") ---@return string function M.get_script_path() @@ -148,13 +160,13 @@ function M.get_runner(python_path) return "unittest" end if - vim_test_runner and lib.func_util.index({ "unittest", "pytest", "django" }, vim_test_runner) + vim_test_runner and lib.func_util.index({ "unittest", "pytest", "django" }, vim_test_runner) then return vim_test_runner end local runner = M.module_exists("pytest", python_path) and "pytest" - or M.module_exists("django", python_path) and "django" - or "unittest" + or M.module_exists("django", python_path) and "django" + or "unittest" stored_runners[command_str] = runner return runner end