Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions crates/uv/tests/it/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,17 +486,24 @@ impl TestContext {

/// Use a shared global cache for Python downloads.
#[must_use]
pub fn with_python_download_cache(mut self) -> Self {
self.extra_env.push((
EnvVars::UV_PYTHON_CACHE_DIR.into(),
// Respect `UV_PYTHON_CACHE_DIR` if set, or use the default cache directory
env::var_os(EnvVars::UV_PYTHON_CACHE_DIR).unwrap_or_else(|| {
uv_cache::Cache::from_settings(false, None)
.unwrap()
.bucket(CacheBucket::Python)
.into()
}),
));
fn with_python_download_cache(mut self) -> Self {
let key: OsString = EnvVars::UV_PYTHON_CACHE_DIR.into();
self.extra_env.retain(|(existing, _)| existing != &key);
let value = env::var_os(EnvVars::UV_PYTHON_CACHE_DIR).unwrap_or_else(|| {
uv_cache::Cache::from_settings(false, None)
.unwrap()
.bucket(CacheBucket::Python)
.into()
});
self.extra_env.push((key, value));
self
}

/// Disable the shared global cache for Python downloads.
#[must_use]
pub fn without_python_download_cache(mut self) -> Self {
let key: OsString = EnvVars::UV_PYTHON_CACHE_DIR.into();
self.extra_env.retain(|(existing, _)| existing != &key);
self
}

Expand All @@ -514,6 +521,8 @@ impl TestContext {
pub fn with_managed_python_dirs(mut self) -> Self {
let managed = self.temp_dir.join("managed");

self = self.with_python_download_cache();

self.extra_env.push((
EnvVars::UV_PYTHON_BIN_DIR.into(),
self.bin_dir.as_os_str().to_owned(),
Expand Down
13 changes: 3 additions & 10 deletions crates/uv/tests/it/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13121,7 +13121,6 @@ fn pip_install_no_sources_editable_to_registry_switch() -> Result<()> {
#[test]
fn install_with_system_interpreter() {
let context = TestContext::new_with_versions(&[])
.with_python_download_cache()
.with_managed_python_dirs()
.with_filtered_python_keys();

Expand Down Expand Up @@ -13151,9 +13150,7 @@ fn install_with_system_interpreter() {
#[test]
fn install_missing_python_no_target() {
// Create a context that only has Python 3.11 available.
let context = TestContext::new("3.11")
.with_python_download_cache()
.with_managed_python_dirs();
let context = TestContext::new("3.11").with_managed_python_dirs();

// Request Python 3.12; which should fail
uv_snapshot!(context.filters(), context.pip_install()
Expand All @@ -13174,9 +13171,7 @@ fn install_missing_python_no_target() {
#[test]
fn install_missing_python_with_target() {
// Create a context with no installed python interpreters.
let context = TestContext::new_with_versions(&[])
.with_python_download_cache()
.with_managed_python_dirs();
let context = TestContext::new_with_versions(&[]).with_managed_python_dirs();

let target_dir = context.temp_dir.child("target-dir");

Expand All @@ -13203,9 +13198,7 @@ fn install_missing_python_with_target() {
#[test]
fn install_missing_python_version_with_target() {
// Create a context that only has Python 3.11 available.
let context = TestContext::new("3.11")
.with_python_download_cache()
.with_managed_python_dirs();
let context = TestContext::new("3.11").with_managed_python_dirs();

let target_dir = context.temp_dir.child("target-dir");

Expand Down
8 changes: 2 additions & 6 deletions crates/uv/tests/it/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6167,9 +6167,7 @@ fn incompatible_platform_direct_url() -> Result<()> {
#[test]
fn sync_missing_python_no_target() -> Result<()> {
// Create a context that only has Python 3.11 available.
let context = TestContext::new("3.11")
.with_python_download_cache()
.with_managed_python_dirs();
let context = TestContext::new("3.11").with_managed_python_dirs();

let requirements = context.temp_dir.child("requirements.txt");
requirements.write_str("anyio")?;
Expand All @@ -6193,9 +6191,7 @@ fn sync_missing_python_no_target() -> Result<()> {
#[test]
fn sync_with_target_installs_missing_python() -> Result<()> {
// Create a context that only has Python 3.11 available.
let context = TestContext::new("3.11")
.with_python_download_cache()
.with_managed_python_dirs();
let context = TestContext::new("3.11").with_managed_python_dirs();

let target_dir = context.temp_dir.child("target-dir");
let requirements = context.temp_dir.child("requirements.txt");
Expand Down
4 changes: 0 additions & 4 deletions crates/uv/tests/it/python_find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1264,7 +1264,6 @@ fn python_find_freethreaded_313() {
.with_filtered_python_keys()
.with_filtered_python_sources()
.with_managed_python_dirs()
.with_python_download_cache()
.with_filtered_python_install_bin()
.with_filtered_python_names()
.with_filtered_exe_suffix();
Expand Down Expand Up @@ -1303,7 +1302,6 @@ fn python_find_freethreaded_314() {
.with_filtered_python_keys()
.with_filtered_python_sources()
.with_managed_python_dirs()
.with_python_download_cache()
.with_filtered_python_install_bin()
.with_filtered_python_names()
.with_filtered_exe_suffix();
Expand Down Expand Up @@ -1380,7 +1378,6 @@ fn python_find_prerelease_version_specifiers() {
.with_filtered_python_keys()
.with_filtered_python_sources()
.with_managed_python_dirs()
.with_python_download_cache()
.with_filtered_python_install_bin()
.with_filtered_python_names()
.with_filtered_exe_suffix();
Expand Down Expand Up @@ -1479,7 +1476,6 @@ fn python_find_prerelease_with_patch_request() {
.with_filtered_python_keys()
.with_filtered_python_sources()
.with_managed_python_dirs()
.with_python_download_cache()
.with_filtered_python_install_bin()
.with_filtered_python_names()
.with_filtered_exe_suffix();
Expand Down
Loading
Loading