@@ -29,10 +29,12 @@ use crate::commands::{elapsed, ExitStatus};
29
29
use crate :: printer:: Printer ;
30
30
31
31
/// Download and install Python versions.
32
+ #[ allow( clippy:: fn_params_excessive_bools) ]
32
33
pub ( crate ) async fn install (
33
34
project_dir : & Path ,
34
35
targets : Vec < String > ,
35
36
reinstall : bool ,
37
+ default : bool ,
36
38
python_downloads : PythonDownloads ,
37
39
native_tls : bool ,
38
40
connectivity : Connectivity ,
@@ -99,6 +101,7 @@ pub(crate) async fn install(
99
101
installation. key( ) . green( ) ,
100
102
) ?;
101
103
}
104
+ // TODO(zanieb): Ensure executables are linked for already-installed versions
102
105
if reinstall {
103
106
uninstalled. insert ( installation. key ( ) ) ;
104
107
unfilled_requests. push ( download_request) ;
@@ -186,35 +189,46 @@ pub(crate) async fn install(
186
189
let managed = ManagedPythonInstallation :: new ( path. clone ( ) ) ?;
187
190
managed. ensure_externally_managed ( ) ?;
188
191
managed. ensure_canonical_executables ( ) ?;
189
- match managed. create_bin_link ( & bin) {
190
- Ok ( executable) => {
191
- debug ! ( "Installed {} executable to {}" , key, executable. display( ) ) ;
192
- }
193
- Err ( uv_python:: managed:: Error :: LinkExecutable { from, to, err } )
194
- if err. kind ( ) == ErrorKind :: AlreadyExists =>
195
- {
196
- // TODO(zanieb): Add `--force`
197
- if reinstall {
198
- fs_err:: remove_file ( & to) ?;
199
- let executable = managed. create_bin_link ( & bin) ?;
200
- debug ! (
201
- "Replaced {} executable at {}" ,
202
- key,
203
- executable. user_display( )
204
- ) ;
205
- } else {
206
- if !is_same_file ( & to, & from) . unwrap_or_default ( ) {
207
- errors. push ( (
208
- key,
209
- anyhow:: anyhow!(
210
- "Executable already exists at `{}`. Use `--reinstall` to force replacement." ,
211
- to. user_display( )
212
- ) ,
213
- ) ) ;
192
+
193
+ // TODO(zanieb): Only apply `default` for the _first_ requested version
194
+ let targets = if default {
195
+ vec ! [
196
+ managed. key( ) . executable_name_minor( ) ,
197
+ managed. key( ) . executable_name_major( ) ,
198
+ managed. key( ) . executable_name( ) ,
199
+ ]
200
+ } else {
201
+ vec ! [ managed. key( ) . executable_name_minor( ) ]
202
+ } ;
203
+
204
+ for target in targets {
205
+ let target = bin. join ( target) ;
206
+ match managed. create_bin_link ( & target) {
207
+ Ok ( ( ) ) => {
208
+ debug ! ( "Installed {} executable to {}" , key, target. display( ) ) ;
209
+ }
210
+ Err ( uv_python:: managed:: Error :: LinkExecutable { from, to, err } )
211
+ if err. kind ( ) == ErrorKind :: AlreadyExists =>
212
+ {
213
+ // TODO(zanieb): Add `--force`
214
+ if reinstall {
215
+ fs_err:: remove_file ( & to) ?;
216
+ managed. create_bin_link ( & target) ?;
217
+ debug ! ( "Replaced {} executable at {}" , key, target. user_display( ) ) ;
218
+ } else {
219
+ if !is_same_file ( & to, & from) . unwrap_or_default ( ) {
220
+ errors. push ( (
221
+ key,
222
+ anyhow:: anyhow!(
223
+ "Executable already exists at `{}`. Use `--reinstall` to force replacement." ,
224
+ to. user_display( )
225
+ ) ,
226
+ ) ) ;
227
+ }
214
228
}
215
229
}
230
+ Err ( err) => return Err ( err. into ( ) ) ,
216
231
}
217
- Err ( err) => return Err ( err. into ( ) ) ,
218
232
}
219
233
}
220
234
Err ( err) => {
@@ -280,7 +294,7 @@ pub(crate) async fn install(
280
294
" {} {} ({})" ,
281
295
"+" . green( ) ,
282
296
event. key. bold( ) ,
283
- event. key. versioned_executable_name ( )
297
+ event. key. executable_name_minor ( )
284
298
) ?;
285
299
}
286
300
ChangeEventKind :: Removed => {
@@ -289,7 +303,7 @@ pub(crate) async fn install(
289
303
" {} {} ({})" ,
290
304
"-" . red( ) ,
291
305
event. key. bold( ) ,
292
- event. key. versioned_executable_name ( )
306
+ event. key. executable_name_minor ( )
293
307
) ?;
294
308
}
295
309
ChangeEventKind :: Reinstalled => {
@@ -298,7 +312,7 @@ pub(crate) async fn install(
298
312
" {} {} ({})" ,
299
313
"~" . yellow( ) ,
300
314
event. key. bold( ) ,
301
- event. key. versioned_executable_name ( )
315
+ event. key. executable_name_minor ( )
302
316
) ?;
303
317
}
304
318
}
0 commit comments