@@ -21,6 +21,8 @@ use settings::PipTreeSettings;
2121use tokio:: task:: spawn_blocking;
2222use tracing:: { debug, instrument, trace} ;
2323
24+ #[ cfg( not( feature = "self-update" ) ) ]
25+ use crate :: install_source:: InstallSource ;
2426use uv_cache:: { Cache , Refresh } ;
2527use uv_cache_info:: Timestamp ;
2628#[ cfg( feature = "self-update" ) ]
@@ -59,6 +61,8 @@ use crate::settings::{
5961
6062pub ( crate ) mod child;
6163pub ( crate ) mod commands;
64+ #[ cfg( not( feature = "self-update" ) ) ]
65+ mod install_source;
6266pub ( crate ) mod logging;
6367pub ( crate ) mod printer;
6468pub ( crate ) mod settings;
@@ -1223,10 +1227,25 @@ async fn run(mut cli: Cli) -> Result<ExitStatus> {
12231227 }
12241228 #[ cfg( not( feature = "self-update" ) ) ]
12251229 Commands :: Self_ ( _) => {
1226- anyhow:: bail!(
1227- "uv was installed through an external package manager, and self-update \
1228- is not available. Please use your package manager to update uv."
1229- ) ;
1230+ const BASE_MESSAGE : & str =
1231+ "uv was installed through an external package manager and cannot update itself." ;
1232+
1233+ let message = match InstallSource :: detect ( ) {
1234+ Some ( source) => format ! (
1235+ concat!(
1236+ "{base}" ,
1237+ "\n " ,
1238+ "\n " ,
1239+ "hint: You installed uv using {}. To update uv, run:\n `{}`"
1240+ ) ,
1241+ source. description( ) ,
1242+ source. update_instructions( ) . green( ) ,
1243+ base = BASE_MESSAGE
1244+ ) ,
1245+ None => format ! ( "{BASE_MESSAGE} Please use your package manager to update uv." )
1246+ } ;
1247+
1248+ anyhow:: bail!( message) ;
12301249 }
12311250 Commands :: GenerateShellCompletion ( args) => {
12321251 args. shell . generate ( & mut Cli :: command ( ) , & mut stdout ( ) ) ;
0 commit comments