fix: handle missing pipenv/poetry

See #10
This commit is contained in:
Rónán Carrigan
2022-07-10 17:19:55 +01:00
parent 4d915fbefd
commit 023b7bda64
2 changed files with 20 additions and 17 deletions

View File

@@ -46,22 +46,30 @@ function M.get_python_command(root)
end end
if lib.files.exists("Pipfile") then if lib.files.exists("Pipfile") then
local _, data = lib.process.run({ "pipenv", "--py" }, { stdout = true }) local success, _, data = pcall(lib.process.run, { "pipenv", "--py" }, { stdout = true })
if success then
local venv = data.stdout:gsub("\n", "") local venv = data.stdout:gsub("\n", "")
if venv then if venv then
python_command_mem[root] = { Path:new(venv).filename } python_command_mem[root] = { Path:new(venv).filename }
return python_command_mem[root] return python_command_mem[root]
end end
end end
end
if lib.files.exists("pyproject.toml") then if lib.files.exists("pyproject.toml") then
local _, data = lib.process.run({ "poetry", "env", "info", "-p" }, { stdout = true }) local success, _, data = pcall(
lib.process.run,
{ "poetry", "env", "info", "-p" },
{ stdout = true }
)
if success then
local venv = data.stdout:gsub("\n", "") local venv = data.stdout:gsub("\n", "")
if venv then if venv then
python_command_mem[root] = { Path:new(venv, "bin", "python").filename } python_command_mem[root] = { Path:new(venv, "bin", "python").filename }
return python_command_mem[root] return python_command_mem[root]
end end
end end
end
-- Fallback to system Python. -- Fallback to system Python.
python_command_mem[root] = { python_command_mem[root] = {

View File

@@ -58,13 +58,8 @@ end
---@type neotest.Adapter ---@type neotest.Adapter
local PythonNeotestAdapter = { name = "neotest-python" } local PythonNeotestAdapter = { name = "neotest-python" }
PythonNeotestAdapter.root = lib.files.match_root_pattern( PythonNeotestAdapter.root =
"pyproject.toml", lib.files.match_root_pattern("pyproject.toml", "setup.cfg", "mypy.ini", "pytest.ini", "setup.py")
"setup.cfg",
"mypy.ini",
"pytest.ini",
"setup.py"
)
function PythonNeotestAdapter.is_test_file(file_path) function PythonNeotestAdapter.is_test_file(file_path)
return is_test_file(file_path) return is_test_file(file_path)