@@ -33,11 +33,20 @@ local function resolve_python3(candidates)
3333 a .scheduler ()
3434 local available_candidates = _ .filter (is_executable , candidates )
3535 for __ , candidate in ipairs (available_candidates ) do
36- --- @type string
37- local version_output = spawn [candidate ]({ " --version" }):map (_ .prop " stdout" ):get_or_else " "
38- local ok , version = pcall (semver .new , version_output :match " Python (3%.%d+.%d+)" )
39- if ok then
40- return { executable = candidate , version = version }
36+ if use_uv and candidate == " uv" then
37+ --- @type string
38+ local version_output = spawn [candidate ]({ " --version" }):map (_ .prop " stdout" ):get_or_else " "
39+ local ok , version = pcall (semver .new , version_output :match " uv (%d+.%d+.%d+).*" )
40+ if ok then
41+ return { executable = candidate , version = version }
42+ end
43+ elseif not use_uv then
44+ --- @type string
45+ local version_output = spawn [candidate ]({ " --version" }):map (_ .prop " stdout" ):get_or_else " "
46+ local ok , version = pcall (semver .new , version_output :match " Python (3%.%d+.%d+)" )
47+ if ok then
48+ return { executable = candidate , version = version }
49+ end
4150 end
4251 end
4352 return nil
@@ -88,13 +97,19 @@ local function create_venv(pkg)
8897
8998 -- 1. Resolve stock python3 installation.
9099 local stock_candidates = platform .is .win and { " python" , " python3" } or { " python3" , " python" }
100+ if use_uv then
101+ table.insert (stock_candidates , 1 , " uv" )
102+ end
91103 local stock_target = resolve_python3 (stock_candidates )
92104 if stock_target then
93105 log .fmt_debug (" Resolved stock python3 installation version %s" , stock_target .version )
94106 end
95107
96108 -- 2. Resolve suitable versioned python3 installation (python3.12, python3.11, etc.).
97109 local versioned_candidates = {}
110+ if use_uv then
111+ table.insert (versioned_candidates , " uv" )
112+ end
98113 if supported_python_versions ~= nil then
99114 if stock_target and not pep440_check_version (tostring (stock_target .version ), supported_python_versions ) then
100115 log .fmt_debug (" Finding versioned candidates for %s" , supported_python_versions )
@@ -114,7 +129,8 @@ local function create_venv(pkg)
114129 -- 3. If a versioned python3 installation was not found, warn the user if the stock python3 installation is outside
115130 -- the supported version range.
116131 if
117- target == stock_target
132+ use_uv == false
133+ and target == stock_target
118134 and supported_python_versions ~= nil
119135 and not pep440_check_version (tostring (target .version ), supported_python_versions )
120136 then
@@ -136,9 +152,14 @@ local function create_venv(pkg)
136152 end
137153 end
138154
139- log .fmt_debug (" Found python3 installation version=%s, executable=%s" , target .version , target .executable )
140155 ctx .stdio_sink :stdout " Creating virtual environment…\n "
141- return ctx .spawn [target .executable ] { " -m" , " venv" , " --system-site-packages" , VENV_DIR }
156+ if use_uv then
157+ log .fmt_debug (" Found uv installation version=%s, executable=%s" , target .version , target .executable )
158+ return ctx .spawn [target .executable ] { " venv" , VENV_DIR }
159+ else
160+ log .fmt_debug (" Found python3 installation version=%s, executable=%s" , target .version , target .executable )
161+ return ctx .spawn [target .executable ] { " -m" , " venv" , " --system-site-packages" , VENV_DIR }
162+ end
142163end
143164
144165--- @param ctx InstallContext
165186--- @param args SpawnArgs
166187local function venv_python (args )
167188 local ctx = installer .context ()
168- return find_venv_executable (ctx , " python" ):and_then (function (bin_path )
169- return ctx .spawn [path .concat { ctx .cwd :get (), bin_path }](args )
189+ if use_uv then
190+ return ctx .spawn [" uv" ](args )
191+ end
192+ return find_venv_executable (ctx , " python" ):and_then (function (python_path )
193+ return ctx .spawn [path .concat { ctx .cwd :get (), python_path }](args )
170194 end )
171195end
172196
@@ -219,7 +243,7 @@ function M.init(opts)
219243 ctx :promote_cwd ()
220244 try (create_venv (opts .package ))
221245
222- if opts .upgrade_pip then
246+ if opts .upgrade_pip and not use_uv then
223247 ctx .stdio_sink :stdout " Upgrading pip inside the virtual environment…\n "
224248 try (pip_install ({ " pip" }, opts .install_extra_args ))
225249 end
@@ -245,13 +269,17 @@ end
245269--- @param pkg string
246270function M .uninstall (pkg )
247271 log .fmt_debug (" pypi: uninstall %s" , pkg )
248- return venv_python {
249- " -m" ,
250- " pip" ,
251- " uninstall" ,
252- " -y" ,
253- pkg ,
254- }
272+ if use_uv then
273+ return venv_python { " pip" , " uninstall" , " -y" , pkg }
274+ else
275+ return venv_python {
276+ " -m" ,
277+ " pip" ,
278+ " uninstall" ,
279+ " -y" ,
280+ pkg ,
281+ }
282+ end
255283end
256284
257285--- @param executable string
0 commit comments