From 143aacd04e2bdb42cf51e62bb3cef58da43a8ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3n=C3=A1n=20Carrigan?= Date: Sat, 1 Oct 2022 14:48:18 +0100 Subject: [PATCH] fix: search runtime for python script See https://github.com/nvim-neotest/neotest/issues/118 --- lua/neotest-python/init.lua | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lua/neotest-python/init.lua b/lua/neotest-python/init.lua index 7a37023..4359a49 100644 --- a/lua/neotest-python/init.lua +++ b/lua/neotest-python/init.lua @@ -1,14 +1,17 @@ local async = require("neotest.async") -local Path = require("plenary.path") local lib = require("neotest.lib") local base = require("neotest-python.base") -local function script_path() - local str = debug.getinfo(2, "S").source:sub(2) - return str:match(("(.*%s)"):format(lib.files.sep)) -end +local function get_script() + local paths = vim.api.nvim_get_runtime_file("neotest.py", true) + for _, path in ipairs(paths) do + if vim.endswith(path, ("neotest-python%sneotest.py"):format(lib.files.sep)) then + return path + end + end -local python_script = (Path.new(script_path()):parent():parent() / "neotest.py").filename + error("neotest.py not found") +end local dap_args local is_test_file = base.is_test_file @@ -104,9 +107,7 @@ function PythonNeotestAdapter.build_spec(args) local position = args.tree:data() local results_path = async.fn.tempname() local stream_path = async.fn.tempname() - local x = io.open(stream_path, "w") - x:write("") - x:close() + lib.files.write(stream_path, "") local root = PythonNeotestAdapter.root(position.path) local python = get_python(root) @@ -127,7 +128,7 @@ function PythonNeotestAdapter.build_spec(args) end local command = vim.tbl_flatten({ python, - python_script, + get_script(), script_args, }) local strategy_config = get_strategy_config(args.strategy, python, python_script, script_args)