@@ -15,28 +15,34 @@ local spawn = require "mason-core.spawn"
1515local  M  =  {}
1616
1717local  use_uv  =  settings .current .pip .use_uv 
18- local  VENV_DIR  =  " venv" 
18+ local  VENV_DIR 
19+ if  use_uv  then 
20+     VENV_DIR  =  " .venv" 
21+ else 
22+     VENV_DIR  =  " venv" 
23+ end 
1924
2025--- @async 
2126--- @param  candidates  string[] 
2227local  function  resolve_python3 (candidates )
2328    local  is_executable  =  _ .compose (_ .equals (1 ), vim .fn .executable )
2429    a .scheduler ()
25-     if  use_uv  then 
26-         candidates  =  { " uv"  
27-     end 
2830    local  available_candidates  =  _ .filter (is_executable , candidates )
2931    for  __ , candidate  in  ipairs (available_candidates ) do 
30-         --- @type  string 
31-         local  version_output  =  spawn [candidate ]({ " --version"  map (_ .prop  " stdout" get_or_else  " " 
32-         local  ok , version 
33-         if  use_uv  then 
34-             ok , version  =  pcall (semver .new , version_output :match  " uv (%d+.%d+.%d+)" 
35-         else 
36-             ok , version  =  pcall (semver .new , version_output :match  " Python (3%.%d+.%d+)" 
37-         end 
38-         if  ok  then 
39-             return  { executable  =  candidate , version  =  version  }
32+         if  use_uv  and  candidate  ==  " uv"  then 
33+             --- @type  string 
34+             local  version_output  =  spawn [candidate ]({ " --version"  map (_ .prop  " stdout" get_or_else  " " 
35+             local  ok , version  =  pcall (semver .new , version_output :match  " uv (%d+.%d+.%d+).*" 
36+             if  ok  then 
37+                 return  { executable  =  candidate , version  =  version  }
38+             end 
39+         elseif  not  use_uv  then 
40+             --- @type  string 
41+             local  version_output  =  spawn [candidate ]({ " --version"  map (_ .prop  " stdout" get_or_else  " " 
42+             local  ok , version  =  pcall (semver .new , version_output :match  " Python (3%.%d+.%d+)" 
43+             if  ok  then 
44+                 return  { executable  =  candidate , version  =  version  }
45+             end 
4046        end 
4147    end 
4248    return  nil 
@@ -86,14 +92,14 @@ local function create_venv(pkg)
8692    local  supported_python_versions  =  providers .pypi .get_supported_python_versions (pkg .name , pkg .version ):get_or_nil ()
8793
8894    --  1. Resolve stock python3 installation.
89-     local  stock_candidates  =  platform .is .win  and  { " python" " python3"   or  { " python3" " python"  
95+     local  stock_candidates  =  platform .is .win  and  { " python" " python3" ,  " uv "  or  { " python3" " python" ,  " uv "  
9096    local  stock_target  =  resolve_python3 (stock_candidates )
9197    if  stock_target  then 
9298        log .fmt_debug (" Resolved stock python3 installation version %s" stock_target .version )
9399    end 
94100
95101    --  2. Resolve suitable versioned python3 installation (python3.12, python3.11, etc.).
96-     local  versioned_candidates  =  {}
102+     local  versioned_candidates  =  {  " uv "  
97103    if  supported_python_versions  ~=  nil  then 
98104        if  stock_target  and  not  pep440_check_version (tostring (stock_target .version ), supported_python_versions ) then 
99105            log .fmt_debug (" Finding versioned candidates for %s" supported_python_versions )
@@ -113,7 +119,8 @@ local function create_venv(pkg)
113119    --  3. If a versioned python3 installation was not found, warn the user if the stock python3 installation is outside
114120    --  the supported version range.
115121    if 
116-         target  ==  stock_target 
122+         use_uv  ==  false 
123+         and  target  ==  stock_target 
117124        and  supported_python_versions  ~=  nil 
118125        and  not  pep440_check_version (tostring (target .version ), supported_python_versions )
119126    then 
@@ -135,9 +142,7 @@ local function create_venv(pkg)
135142        end 
136143    end 
137144
138-     log .fmt_debug (" Found python3 installation version=%s, executable=%s" target .version , target .executable )
139145    ctx .stdio_sink .stdout  " Creating virtual environment…\n " 
140- 
141146    if  use_uv  then 
142147        log .fmt_debug (" Found uv installation version=%s, executable=%s" target .version , target .executable )
143148        return  ctx .spawn [target .executable ] { " venv" VENV_DIR  }
170175--- @param  args  SpawnArgs 
171176local  function  venv_python (args )
172177    local  ctx  =  installer .context ()
178+     if  use_uv  then 
179+         return  ctx .spawn [{ " uv" " venv"  args )
180+     end 
173181    return  find_venv_executable (ctx , " python" and_then (function (python_path )
174182        return  ctx .spawn [path .concat  { ctx .cwd :get (), python_path  }](args )
175183    end )
@@ -181,14 +189,14 @@ end
181189local  function  pip_install (pkgs , extra_args )
182190    if  use_uv  then 
183191        local  ctx  =  installer .context ()
192+ 
184193        local  task  =  ctx .spawn [" uv" 
185194            " pip" 
186195            " install" 
187196            " -U" 
188197            extra_args  or  vim .NIL ,
189198            pkgs ,
190199        }
191-         --  vim.api.nvim_set_current_dir(curdir)
192200        return  task 
193201    else 
194202        return  venv_python  {
0 commit comments