@@ -9,22 +9,32 @@ local pep440 = require "mason-core.pep440"
99local platform = require " mason-core.platform"
1010local providers = require " mason-core.providers"
1111local semver = require " mason-core.semver"
12+ local settings = require " mason.settings"
1213local spawn = require " mason-core.spawn"
1314
1415local M = {}
1516
17+ local use_uv = settings .current .pip .use_uv
1618local VENV_DIR = " venv"
1719
1820--- @async
1921--- @param candidates string[]
2022local function resolve_python3 (candidates )
2123 local is_executable = _ .compose (_ .equals (1 ), vim .fn .executable )
2224 a .scheduler ()
25+ if use_uv then
26+ candidates = { " uv" }
27+ end
2328 local available_candidates = _ .filter (is_executable , candidates )
2429 for __ , candidate in ipairs (available_candidates ) do
2530 --- @type string
2631 local version_output = spawn [candidate ]({ " --version" }):map (_ .prop " stdout" ):get_or_else " "
27- local ok , version = pcall (semver .new , version_output :match " Python (3%.%d+.%d+)" )
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
2838 if ok then
2939 return { executable = candidate , version = version }
3040 end
@@ -127,7 +137,14 @@ local function create_venv(pkg)
127137
128138 log .fmt_debug (" Found python3 installation version=%s, executable=%s" , target .version , target .executable )
129139 ctx .stdio_sink .stdout " Creating virtual environment…\n "
130- return ctx .spawn [target .executable ] { " -m" , " venv" , " --system-site-packages" , VENV_DIR }
140+
141+ if use_uv then
142+ log .fmt_debug (" Found uv installation version=%s, executable=%s" , target .version , target .executable )
143+ return ctx .spawn [target .executable ] { " venv" , VENV_DIR }
144+ else
145+ log .fmt_debug (" Found python3 installation version=%s, executable=%s" , target .version , target .executable )
146+ return ctx .spawn [target .executable ] { " -m" , " venv" , " --system-site-packages" , VENV_DIR }
147+ end
131148end
132149
133150--- @param ctx InstallContext
@@ -162,16 +179,29 @@ end
162179--- @param pkgs string[]
163180--- @param extra_args ? string[]
164181local function pip_install (pkgs , extra_args )
165- return venv_python {
166- " -m" ,
167- " pip" ,
168- " --disable-pip-version-check" ,
169- " install" ,
170- " --ignore-installed" ,
171- " -U" ,
172- extra_args or vim .NIL ,
173- pkgs ,
174- }
182+ if use_uv then
183+ local ctx = installer .context ()
184+ local task = ctx .spawn [" uv" ] {
185+ " pip" ,
186+ " install" ,
187+ " -U" ,
188+ extra_args or vim .NIL ,
189+ pkgs ,
190+ }
191+ -- vim.api.nvim_set_current_dir(curdir)
192+ return task
193+ else
194+ return venv_python {
195+ " -m" ,
196+ " pip" ,
197+ " --disable-pip-version-check" ,
198+ " install" ,
199+ " --ignore-installed" ,
200+ " -U" ,
201+ extra_args or vim .NIL ,
202+ pkgs ,
203+ }
204+ end
175205end
176206
177207--- @async
@@ -185,7 +215,7 @@ function M.init(opts)
185215 ctx :promote_cwd ()
186216 try (create_venv (opts .package ))
187217
188- if opts .upgrade_pip then
218+ if opts .upgrade_pip and not use_uv then
189219 ctx .stdio_sink .stdout " Upgrading pip inside the virtual environment…\n "
190220 try (pip_install ({ " pip" }, opts .install_extra_args ))
191221 end
0 commit comments