From 77fe8d2e60b4c749b07d1fbbeb89be3bd61fe33a Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Fri, 15 Aug 2025 08:06:52 -0500 Subject: [PATCH] Move python bin filtering into test that needs it (#15305) Closes #15188 --- crates/uv/tests/it/common/mod.rs | 23 ----------------------- crates/uv/tests/it/python_module.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index 28cadfdfe..5737aae4f 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -600,29 +600,6 @@ impl TestContext { .map(|pattern| (pattern.to_string(), format!("[PYTHON-{version}]"))), ); - // Add filtering for the bin directory of the base interpreter path - let bin_dir = if cfg!(windows) { - // On Windows, the Python executable is in the root, not the bin directory - executable - .canonicalize() - .unwrap() - .parent() - .unwrap() - .join("Scripts") - } else { - executable - .canonicalize() - .unwrap() - .parent() - .unwrap() - .to_path_buf() - }; - filters.extend( - Self::path_patterns(bin_dir) - .into_iter() - .map(|pattern| (pattern.to_string(), format!("[PYTHON-BIN-{version}]"))), - ); - // And for the symlink we created in the test the Python path filters.extend( Self::path_patterns(python_dir.join(version.to_string())) diff --git a/crates/uv/tests/it/python_module.rs b/crates/uv/tests/it/python_module.rs index 352c159f4..a9570ccd6 100644 --- a/crates/uv/tests/it/python_module.rs +++ b/crates/uv/tests/it/python_module.rs @@ -385,7 +385,7 @@ fn find_uv_bin_user_bin() { #[test] fn find_uv_bin_error_message() { - let context = TestContext::new("3.12") + let mut context = TestContext::new("3.12") .with_filtered_python_names() .with_filtered_virtualenv_bin() .with_filtered_exe_suffix() @@ -394,6 +394,29 @@ fn find_uv_bin_error_message() { // `with_filtered_virtualenv_bin` only filters "Scripts", not "bin" .with_filter((r"[\\/]bin".to_string(), "/[BIN]".to_string())); + // Add filters for Python bin directories using with_filtered_path + // This inserts at the beginning, so these filters are applied first + let python_info: Vec<_> = context.python_versions.clone(); + for (version, executable) in &python_info { + let bin_dir = if cfg!(windows) { + // On Windows, the Python executable is in the root, not the bin directory + executable + .canonicalize() + .unwrap() + .parent() + .unwrap() + .join("Scripts") + } else { + executable + .canonicalize() + .unwrap() + .parent() + .unwrap() + .to_path_buf() + }; + context = context.with_filtered_path(&bin_dir, &format!("PYTHON-BIN-{version}")); + } + // Install in a virtual environment uv_snapshot!(context.filters(), context.pip_install() .arg(context.workspace_root.join("scripts/packages/fake-uv")), @r" @@ -431,7 +454,7 @@ fn find_uv_bin_error_message() { raise UvNotFound( uv._find_uv.UvNotFound: Could not find the uv binary in any of the following locations: - [VENV]/[BIN] - - [PYTHON-BIN-3.12] + - [PYTHON-BIN-3.12]/ - [SITE_PACKAGES]/[BIN] - [USER_SCHEME]/[BIN] "#