Skip to content

Commit bd2907d

Browse files
clippy + formatting
Signed-off-by: Mikayla Thompson <[email protected]>
1 parent ee2208b commit bd2907d

File tree

5 files changed

+80
-86
lines changed

5 files changed

+80
-86
lines changed

crates/uv-client/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ pub use base_client::{
33
RedirectClientWithMiddleware, RequestBuilder, RetryParsingError, UvRetryableStrategy,
44
is_transient_network_error,
55
};
6-
pub use cached_client::{CacheControl, CachedClient, CachedClientError, DataWithCachePolicy, PreDownloadHook};
6+
pub use cached_client::{
7+
CacheControl, CachedClient, CachedClientError, DataWithCachePolicy, PreDownloadHook,
8+
};
79
pub use error::{Error, ErrorKind, WrappedReqwestError};
810
pub use flat_index::{FlatIndexClient, FlatIndexEntries, FlatIndexEntry, FlatIndexError};
911
pub use linehaul::LineHaul;

crates/uv-client/src/registry_client.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ pub struct RegistryClientBuilder<'a> {
5858
pre_download_hook: Option<PreDownloadHook>,
5959
}
6060

61-
6261
impl<'a> RegistryClientBuilder<'a> {
6362
pub fn new(base_client_builder: BaseClientBuilder<'a>, cache: Cache) -> Self {
6463
Self {
@@ -75,8 +74,7 @@ impl<'a> RegistryClientBuilder<'a> {
7574
/// The hook receives the URL and returns `Ok(true)` to proceed with download,
7675
/// `Ok(false)` to cancel, or `Err` on error.
7776
#[must_use]
78-
pub fn pre_download_hook(mut self, hook: PreDownloadHook) -> Self
79-
{
77+
pub fn pre_download_hook(mut self, hook: PreDownloadHook) -> Self {
8078
self.pre_download_hook = Some(hook);
8179
self
8280
}

crates/uv/src/commands/project/environment.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use tracing::debug;
55
use crate::commands::pip::loggers::{InstallLogger, ResolveLogger};
66
use crate::commands::pip::operations::Modifications;
77
use crate::commands::project::{
8-
EnvironmentSpecification, PlatformState, ProjectError, sync_environment,
8+
EnvironmentSpecification, PlatformState, ProjectError, resolve_environment_with_hook,
9+
sync_environment,
910
};
1011
use crate::printer::Printer;
1112
use crate::settings::ResolverInstallerSettings;
@@ -167,7 +168,7 @@ impl CachedEnvironment {
167168

168169
// Resolve the requirements with the interpreter.
169170
let resolution = Resolution::from(
170-
crate::commands::project::resolve_environment_with_hook(
171+
resolve_environment_with_hook(
171172
spec,
172173
&interpreter,
173174
python_platform,

crates/uv/src/commands/tool/run.rs

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ use uv_python::{
3838
PythonPreference, PythonRequest,
3939
};
4040
use uv_requirements::{RequirementsSource, RequirementsSpecification};
41-
use uv_settings::{InstallPromptHeuristic, PythonInstallMirrors, ResolverInstallerOptions, ToolOptions};
41+
use uv_settings::{
42+
InstallPromptHeuristic, PythonInstallMirrors, ResolverInstallerOptions, ToolOptions,
43+
};
4244
use uv_shell::runnable::WindowsRunnable;
4345
use uv_static::EnvVars;
4446
use 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.
147152
fn 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-
"{}\nNon-interactive mode: installation will proceed automatically.",
203-
prompt_message
207+
"{prompt_message}\nNon-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,

crates/uv/tests/it/tool_run.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3176,9 +3176,9 @@ fn tool_run_install_confirmation() -> anyhow::Result<()> {
31763176

31773177
// Create uv.toml with empty heuristics to disable top-packages check
31783178
let config = context.temp_dir.child("uv.toml");
3179-
config.write_str(indoc::indoc! {r#"
3179+
config.write_str(indoc::indoc! {r"
31803180
approve-all-heuristics = []
3181-
"#})?;
3181+
"})?;
31823182

31833183
// Run with preview flag enabled and tool-install-confirmation feature
31843184
// Use a package not in top-packages list to trigger prompt
@@ -3226,7 +3226,7 @@ fn tool_run_install_confirmation() -> anyhow::Result<()> {
32263226

32273227
/// Test that tool install confirmation prompt is NOT shown when preview flag is disabled.
32283228
#[test]
3229-
fn tool_run_install_confirmation_preview_disabled() -> anyhow::Result<()> {
3229+
fn tool_run_install_confirmation_preview_disabled() {
32303230
let context = TestContext::new("3.12");
32313231
let tool_dir = context.temp_dir.child("tools");
32323232
let bin_dir = context.temp_dir.child("bin");
@@ -3254,8 +3254,6 @@ fn tool_run_install_confirmation_preview_disabled() -> anyhow::Result<()> {
32543254
+ pathspec==0.12.1
32553255
+ platformdirs==4.2.0
32563256
"###);
3257-
3258-
Ok(())
32593257
}
32603258

32613259
/// Test that tool install confirmation is skipped when --approve-all-tool-installs is set.
@@ -3267,9 +3265,9 @@ fn tool_run_install_confirmation_approve_all_flag() -> anyhow::Result<()> {
32673265

32683266
// Create uv.toml with empty heuristics list
32693267
let config = context.temp_dir.child("uv.toml");
3270-
config.write_str(indoc::indoc! {r#"
3268+
config.write_str(indoc::indoc! {r"
32713269
approve-all-heuristics = []
3272-
"#})?;
3270+
"})?;
32733271

32743272
// Run with --approve-all-tool-installs flag and preview enabled - should not prompt
32753273
uv_snapshot!(context.filters(), context.tool_run()
@@ -3304,10 +3302,10 @@ fn tool_run_install_confirmation_approve_all_config() -> anyhow::Result<()> {
33043302

33053303
// Create uv.toml with approve-all-tool-installs = true and empty heuristics list
33063304
let config = context.temp_dir.child("uv.toml");
3307-
config.write_str(indoc::indoc! {r#"
3305+
config.write_str(indoc::indoc! {r"
33083306
approve-all-tool-installs = true
33093307
approve-all-heuristics = []
3310-
"#})?;
3308+
"})?;
33113309

33123310
// Run with preview enabled - should not prompt due to config
33133311
uv_snapshot!(context.filters(), context.tool_run()
@@ -3335,7 +3333,7 @@ fn tool_run_install_confirmation_approve_all_config() -> anyhow::Result<()> {
33353333

33363334
/// Test that tool install confirmation is skipped when package is in top-packages (default heuristic).
33373335
#[test]
3338-
fn tool_run_install_confirmation_top_packages_heuristic() -> anyhow::Result<()> {
3336+
fn tool_run_install_confirmation_top_packages_heuristic() {
33393337
let context = TestContext::new("3.12");
33403338
let tool_dir = context.temp_dir.child("tools");
33413339
let bin_dir = context.temp_dir.child("bin");
@@ -3359,8 +3357,6 @@ fn tool_run_install_confirmation_top_packages_heuristic() -> anyhow::Result<()>
33593357
Installed 1 package in [TIME]
33603358
+ ruff==0.3.4
33613359
"###);
3362-
3363-
Ok(())
33643360
}
33653361

33663362
/// Test that tool install confirmation shows reasoning when package is not in top-packages.
@@ -3410,7 +3406,7 @@ fn tool_run_install_confirmation_reasoning_top_packages() -> anyhow::Result<()>
34103406

34113407
/// Test that tool install confirmation is skipped when package is already cached.
34123408
#[test]
3413-
fn tool_run_install_confirmation_cached_package() -> anyhow::Result<()> {
3409+
fn tool_run_install_confirmation_cached_package() {
34143410
let context = TestContext::new("3.12");
34153411
let tool_dir = context.temp_dir.child("tools");
34163412
let bin_dir = context.temp_dir.child("bin");
@@ -3441,13 +3437,11 @@ fn tool_run_install_confirmation_cached_package() -> anyhow::Result<()> {
34413437
----- stderr -----
34423438
Resolved 1 package in [TIME]
34433439
"###);
3444-
3445-
Ok(())
34463440
}
34473441

34483442
/// Test that tool install confirmation shows message in non-TTY mode with reasoning.
34493443
#[test]
3450-
fn tool_run_install_confirmation_non_tty() -> anyhow::Result<()> {
3444+
fn tool_run_install_confirmation_non_tty() {
34513445
let context = TestContext::new("3.12");
34523446
let tool_dir = context.temp_dir.child("tools");
34533447
let bin_dir = context.temp_dir.child("bin");
@@ -3475,8 +3469,6 @@ fn tool_run_install_confirmation_non_tty() -> anyhow::Result<()> {
34753469
× No solution found when resolving tool dependencies:
34763470
╰─▶ Because a-very-unpopular-python-package was not found in the package registry and you require a-very-unpopular-python-package, we can conclude that your requirements are unsatisfiable.
34773471
"###);
3478-
3479-
Ok(())
34803472
}
34813473

34823474
/// Test that tool install confirmation can be cancelled.
@@ -3525,7 +3517,7 @@ fn tool_run_install_confirmation_cancelled() -> anyhow::Result<()> {
35253517
}
35263518

35273519
#[test]
3528-
fn tool_run_install_confirmation_tool_from_package() -> anyhow::Result<()> {
3520+
fn tool_run_install_confirmation_tool_from_package() {
35293521
let context = TestContext::new("3.12");
35303522
let tool_dir = context.temp_dir.child("tools");
35313523
let bin_dir = context.temp_dir.child("bin");
@@ -3553,6 +3545,4 @@ fn tool_run_install_confirmation_tool_from_package() -> anyhow::Result<()> {
35533545
× No solution found when resolving tool dependencies:
35543546
╰─▶ Because a-very-unpopular-python-package was not found in the package registry and you require a-very-unpopular-python-package, we can conclude that your requirements are unsatisfiable.
35553547
"###);
3556-
3557-
Ok(())
35583548
}

0 commit comments

Comments
 (0)