@@ -38,7 +38,9 @@ use uv_python::{
3838 PythonPreference , PythonRequest ,
3939} ;
4040use uv_requirements:: { RequirementsSource , RequirementsSpecification } ;
41- use uv_settings:: { InstallPromptHeuristic , PythonInstallMirrors , ResolverInstallerOptions , ToolOptions } ;
41+ use uv_settings:: {
42+ InstallPromptHeuristic , PythonInstallMirrors , ResolverInstallerOptions , ToolOptions ,
43+ } ;
4244use uv_shell:: runnable:: WindowsRunnable ;
4345use uv_static:: EnvVars ;
4446use uv_tool:: { InstalledTools , entrypoint_paths} ;
@@ -107,8 +109,11 @@ fn is_top_package(package_name: &PackageName) -> bool {
107109
108110/// Check heuristics and build reasoning string.
109111///
110- /// Returns (should_skip_prompt, reasoning_string)
111- fn check_heuristics ( requirement : & Requirement , enabled_heuristics : & [ InstallPromptHeuristic ] ) -> ( bool , String ) {
112+ /// Returns (`should_skip_prompt`, `reasoning_string`)
113+ fn check_heuristics (
114+ requirement : & Requirement ,
115+ enabled_heuristics : & [ InstallPromptHeuristic ] ,
116+ ) -> ( bool , String ) {
112117 let mut reasoning_parts = Vec :: new ( ) ;
113118 let mut should_skip_prompt = false ;
114119
@@ -143,7 +148,7 @@ fn check_heuristics(requirement: &Requirement, enabled_heuristics: &[InstallProm
143148
144149/// Check if we need to prompt for tool installation and prompt if necessary.
145150///
146- /// Returns Ok(ExitStatus::Success) if we should proceed, Ok(ExitStatus::Failure) if cancelled, Err on error.
151+ /// Returns ` Ok(ExitStatus::Success)` if we should proceed, ` Ok(ExitStatus::Failure)` if cancelled, Err on error.
147152fn check_and_prompt_for_tool_install (
148153 requirement : & Requirement ,
149154 preview : Preview ,
@@ -199,10 +204,9 @@ fn check_and_prompt_for_tool_install(
199204 if !term. is_term ( ) {
200205 debug ! ( "Not a TTY interface, skipping prompt but printing message" ) ;
201206 let message = format ! (
202- "{}\n Non-interactive mode: installation will proceed automatically." ,
203- prompt_message
207+ "{prompt_message}\n Non-interactive mode: installation will proceed automatically."
204208 ) ;
205- writeln ! ( printer. stderr( ) , "{}" , message ) ?;
209+ writeln ! ( printer. stderr( ) , "{message}" ) ?;
206210 return Ok ( ExitStatus :: Success ) ;
207211 }
208212
@@ -212,7 +216,7 @@ fn check_and_prompt_for_tool_install(
212216 requirement. name. as_str( )
213217 ) ;
214218
215- write ! ( printer. stderr( ) , "{} \n " , prompt_message ) ?;
219+ writeln ! ( printer. stderr( ) , "{prompt_message}" ) ?;
216220 match uv_console:: confirm ( "Would you like to proceed?" , & term, true ) {
217221 Ok ( true ) => {
218222 debug ! (
@@ -1047,7 +1051,6 @@ async fn get_or_create_environment(
10471051 )
10481052 . await ?;
10491053
1050-
10511054 // Set up a pre-download hook that prompts before downloading new files.
10521055 // The hook is called before any download happens, allowing us to prompt only when needed.
10531056 // Clone approve_all_heuristics to Vec to own it for the 'static closure
@@ -1065,30 +1068,30 @@ async fn get_or_create_environment(
10651068 let approve_all_heuristics = approve_all_heuristics_arc. clone ( ) ;
10661069 let url = url. clone ( ) ;
10671070
1068- // Check if we've already prompted and got approval
1069- if let Some ( result) = * prompt_approved. lock ( ) . unwrap ( ) {
1070- return Ok ( result) ;
1071- }
1072- debug ! ( "Pre-download hook triggered for: {}" , url) ;
1073-
1074- // Prompt the user
1075- let approved = matches ! (
1076- check_and_prompt_for_tool_install(
1077- & * requirement,
1078- preview,
1079- approve_all_tool_installs,
1080- & * approve_all_heuristics,
1081- printer,
1082- )
1083- . map_err( |_| { Error :: from( ErrorKind :: DownloadCancelled ( url) ) } ) ?,
1084- ExitStatus :: Success
1085- ) ;
1071+ // Check if we've already prompted and got approval
1072+ if let Some ( result) = * prompt_approved. lock ( ) . unwrap ( ) {
1073+ return Ok ( result) ;
1074+ }
1075+ debug ! ( "Pre-download hook triggered for: {}" , url) ;
10861076
1087- // Cache the result
1088- * prompt_approved. lock ( ) . unwrap ( ) = Some ( approved) ;
1077+ // Prompt the user
1078+ let approved = matches ! (
1079+ check_and_prompt_for_tool_install(
1080+ & requirement,
1081+ preview,
1082+ approve_all_tool_installs,
1083+ & approve_all_heuristics,
1084+ printer,
1085+ )
1086+ . map_err( |_| { Error :: from( ErrorKind :: DownloadCancelled ( url) ) } ) ?,
1087+ ExitStatus :: Success
1088+ ) ;
10891089
1090- Ok ( approved)
1091- } ) )
1090+ // Cache the result
1091+ * prompt_approved. lock ( ) . unwrap ( ) = Some ( approved) ;
1092+
1093+ Ok ( approved)
1094+ } ) )
10921095 } else {
10931096 None
10941097 } ;
@@ -1313,35 +1316,35 @@ async fn get_or_create_environment(
13131316 Ok ( environment) => environment,
13141317 Err ( err) => match err {
13151318 ProjectError :: Operation ( err) => {
1316- // If the resolution failed due to the discovered interpreter not satisfying the
1317- // `requires-python` constraint, we can try to refine the interpreter.
1318- //
1319- // For example, if we discovered a Python 3.8 interpreter on the user's machine,
1320- // but the tool requires Python 3.10 or later, we can try to download a
1321- // Python 3.10 interpreter and re-resolve.
1322- let Some ( interpreter) = refine_interpreter (
1323- & interpreter,
1324- python_request. as_ref ( ) ,
1325- & err,
1326- client_builder,
1327- & reporter,
1328- & install_mirrors,
1329- python_preference,
1330- python_downloads,
1331- cache,
1332- preview,
1333- )
1334- . await
1335- . ok ( )
1336- . flatten ( ) else {
1337- return Err ( err. into ( ) ) ;
1338- } ;
1319+ // If the resolution failed due to the discovered interpreter not satisfying the
1320+ // `requires-python` constraint, we can try to refine the interpreter.
1321+ //
1322+ // For example, if we discovered a Python 3.8 interpreter on the user's machine,
1323+ // but the tool requires Python 3.10 or later, we can try to download a
1324+ // Python 3.10 interpreter and re-resolve.
1325+ let Some ( interpreter) = refine_interpreter (
1326+ & interpreter,
1327+ python_request. as_ref ( ) ,
1328+ & err,
1329+ client_builder,
1330+ & reporter,
1331+ & install_mirrors,
1332+ python_preference,
1333+ python_downloads,
1334+ cache,
1335+ preview,
1336+ )
1337+ . await
1338+ . ok ( )
1339+ . flatten ( ) else {
1340+ return Err ( err. into ( ) ) ;
1341+ } ;
13391342
1340- debug ! (
1341- "Re-resolving with Python {} (`{}`)" ,
1342- interpreter. python_version( ) ,
1343- interpreter. sys_executable( ) . display( )
1344- ) ;
1343+ debug ! (
1344+ "Re-resolving with Python {} (`{}`)" ,
1345+ interpreter. python_version( ) ,
1346+ interpreter. sys_executable( ) . display( )
1347+ ) ;
13451348
13461349 CachedEnvironment :: from_spec (
13471350 spec,
0 commit comments