Skip to content

Commit

Permalink
Update pip completions to use sysconfig.
Browse files Browse the repository at this point in the history
distutils.sysconfig has been deprecated for many years.
  • Loading branch information
chrisant996 committed Jul 4, 2024
1 parent bf8839f commit 7c85732
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions pip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,35 @@ local w = require("tables").wrap

local parser = clink.arg.new_parser

local function pip_libs_list(token)
local handle = io.popen('2>nul python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"')
local python_lib_path = handle:read("*a")
handle:close()

-- trim spaces
python_lib_path = python_lib_path:gsub("^%s*(.-)%s*$", "%1")
local function get_packages(dir, token)
local list
if not dir or dir == "" then
list = {}
else
local finder = matchers.create_files_matcher(dir .. "\\*.dist-info")
list = finder(token)
end
return w(list)
end

local finder = matchers.create_files_matcher(python_lib_path .. "\\*.dist-info")
local function pip_libs_list(token)
local sysconfig = {}

local handle = io.popen('2>nul python -m sysconfig')
if handle then
for line in handle:lines() do
local name, value = line:match('^%s+(.-) = "(.*)"%s*$')
if name and value then
sysconfig[name] = value
end
end
handle:close()
end

local list = w(finder(token))
local platlib = get_packages(sysconfig["platlib"], token)
local purelib = get_packages(sysconfig["purelib"], token)

list =
list:map(
local list = platlib:concat(purelib):map(
function(package)
package = package:gsub("-[%d%.]+dist%-info$", "")
return package
Expand Down

0 comments on commit 7c85732

Please sign in to comment.