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,20 +46,28 @@ 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 })
local venv = data.stdout:gsub("\n", "") if success then
if venv then local venv = data.stdout:gsub("\n", "")
python_command_mem[root] = { Path:new(venv).filename } if venv then
return python_command_mem[root] python_command_mem[root] = { Path:new(venv).filename }
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(
local venv = data.stdout:gsub("\n", "") lib.process.run,
if venv then { "poetry", "env", "info", "-p" },
python_command_mem[root] = { Path:new(venv, "bin", "python").filename } { stdout = true }
return python_command_mem[root] )
if success then
local venv = data.stdout:gsub("\n", "")
if venv then
python_command_mem[root] = { Path:new(venv, "bin", "python").filename }
return python_command_mem[root]
end
end end
end end

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)