@@ -104,10 +104,12 @@ impl Changelog {
104
104
}
105
105
106
106
/// Download and install Python versions.
107
+ #[ allow( clippy:: fn_params_excessive_bools) ]
107
108
pub ( crate ) async fn install (
108
109
project_dir : & Path ,
109
110
targets : Vec < String > ,
110
111
reinstall : bool ,
112
+ default : bool ,
111
113
python_downloads : PythonDownloads ,
112
114
native_tls : bool ,
113
115
connectivity : Connectivity ,
@@ -117,6 +119,11 @@ pub(crate) async fn install(
117
119
) -> Result < ExitStatus > {
118
120
let start = std:: time:: Instant :: now ( ) ;
119
121
122
+ if default && !preview. is_enabled ( ) {
123
+ writeln ! ( printer. stderr( ) , "The `--default` flag is only available in preview mode; add the `--preview` flag to use `--default." ) ?;
124
+ return Ok ( ExitStatus :: Failure ) ;
125
+ }
126
+
120
127
// Resolve the requests
121
128
let mut is_default_install = false ;
122
129
let requests: Vec < _ > = if targets. is_empty ( ) {
@@ -269,34 +276,27 @@ pub(crate) async fn install(
269
276
continue ;
270
277
}
271
278
279
+ let targets = if default {
280
+ vec ! [
281
+ installation. key( ) . executable_name_minor( ) ,
282
+ installation. key( ) . executable_name_major( ) ,
283
+ installation. key( ) . executable_name( ) ,
284
+ ]
285
+ } else {
286
+ vec ! [ installation. key( ) . executable_name_minor( ) ]
287
+ } ;
288
+
272
289
let bin = bin
273
290
. as_ref ( )
274
291
. expect ( "We should have a bin directory with preview enabled" )
275
292
. as_path ( ) ;
276
293
277
- match installation. create_bin_link ( bin) {
278
- Ok ( target) => {
279
- debug ! (
280
- "Installed executable at {} for {}" ,
281
- target. user_display( ) ,
282
- installation. key( ) ,
283
- ) ;
284
- changelog. installed . insert ( installation. key ( ) . clone ( ) ) ;
285
- changelog
286
- . installed_executables
287
- . entry ( installation. key ( ) . clone ( ) )
288
- . or_default ( )
289
- . push ( target. clone ( ) ) ;
290
- }
291
- Err ( uv_python:: managed:: Error :: LinkExecutable { from, to, err } )
292
- if err. kind ( ) == ErrorKind :: AlreadyExists =>
293
- {
294
- // TODO(zanieb): Add `--force`
295
- if reinstall {
296
- fs_err:: remove_file ( & to) ?;
297
- let target = installation. create_bin_link ( bin) ?;
294
+ for target in targets {
295
+ let target = bin. join ( target) ;
296
+ match installation. create_bin_link ( & target) {
297
+ Ok ( ( ) ) => {
298
298
debug ! (
299
- "Updated executable at {} to {}" ,
299
+ "Installed executable at {} for {}" ,
300
300
target. user_display( ) ,
301
301
installation. key( ) ,
302
302
) ;
@@ -306,20 +306,40 @@ pub(crate) async fn install(
306
306
. entry ( installation. key ( ) . clone ( ) )
307
307
. or_default ( )
308
308
. push ( target. clone ( ) ) ;
309
- changelog. uninstalled_executables . insert ( target) ;
310
- } else {
311
- if !is_same_file ( & to, & from) . unwrap_or_default ( ) {
312
- errors. push ( (
309
+ }
310
+ Err ( uv_python:: managed:: Error :: LinkExecutable { from, to, err } )
311
+ if err. kind ( ) == ErrorKind :: AlreadyExists =>
312
+ {
313
+ // TODO(zanieb): Add `--force`
314
+ if reinstall {
315
+ fs_err:: remove_file ( & to) ?;
316
+ installation. create_bin_link ( & target) ?;
317
+ debug ! (
318
+ "Updated executable at {} to {}" ,
319
+ target. user_display( ) ,
313
320
installation. key( ) ,
314
- anyhow:: anyhow!(
315
- "Executable already exists at `{}`. Use `--reinstall` to force replacement." ,
316
- to. user_display( )
317
- ) ,
318
- ) ) ;
321
+ ) ;
322
+ changelog. installed . insert ( installation. key ( ) . clone ( ) ) ;
323
+ changelog
324
+ . installed_executables
325
+ . entry ( installation. key ( ) . clone ( ) )
326
+ . or_default ( )
327
+ . push ( target. clone ( ) ) ;
328
+ changelog. uninstalled_executables . insert ( target) ;
329
+ } else {
330
+ if !is_same_file ( & to, & from) . unwrap_or_default ( ) {
331
+ errors. push ( (
332
+ installation. key ( ) ,
333
+ anyhow:: anyhow!(
334
+ "Executable already exists at `{}`. Use `--reinstall` to force replacement." ,
335
+ to. user_display( )
336
+ ) ,
337
+ ) ) ;
338
+ }
319
339
}
320
340
}
341
+ Err ( err) => return Err ( err. into ( ) ) ,
321
342
}
322
- Err ( err) => return Err ( err. into ( ) ) ,
323
343
}
324
344
}
325
345
0 commit comments