Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the cache dir wherever uv is called from when --no-cache specified #11477

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion crates/uv-cache/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Cache {
/// Returns an absolute cache dir.
pub fn from_settings(no_cache: bool, cache_dir: Option<PathBuf>) -> Result<Self, io::Error> {
if no_cache {
Self::temp()
Self::temp(cache_dir)
} else if let Some(cache_dir) = cache_dir {
Ok(Self::from_path(cache_dir))
} else if let Some(cache_dir) = uv_dirs::legacy_user_cache_dir().filter(|dir| dir.exists())
Expand Down
7 changes: 5 additions & 2 deletions crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,11 @@ impl Cache {
}

/// Create a temporary cache directory.
pub fn temp() -> Result<Self, io::Error> {
let temp_dir = tempfile::tempdir()?;
pub fn temp(cache_dir: Option<PathBuf>) -> Result<Self, io::Error> {
let temp_dir = match cache_dir {
Some(dir) => tempfile::tempdir_in(dir)?,
None => tempfile::tempdir_in("")?,
};
Ok(Self {
root: temp_dir.path().to_path_buf(),
refresh: Refresh::None(Timestamp::now()),
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<'a> TryFrom<BaseClientBuilder<'a>> for RegistryClientBuilder<'a> {
Ok(Self {
index_urls: IndexUrls::default(),
index_strategy: IndexStrategy::default(),
cache: Cache::temp()?,
cache: Cache::temp(None)?,
base_client_builder: value,
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/tests/it/remote_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use uv_pep508::VerbatimUrl;

#[tokio::test]
async fn remote_metadata_with_and_without_cache() -> Result<()> {
let cache = Cache::temp()?.init()?;
let cache = Cache::temp(None)?.init()?;
let client = RegistryClientBuilder::new(cache).build();

// The first run is without cache (the tempdir is empty), the second has the cache from the
Expand Down
4 changes: 2 additions & 2 deletions crates/uv-client/tests/it/user_agent_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async fn test_user_agent_has_version() -> Result<()> {
});

// Initialize uv-client
let cache = Cache::temp()?.init()?;
let cache = Cache::temp(None)?.init()?;
let client = RegistryClientBuilder::new(cache).build();

// Send request to our dummy server
Expand Down Expand Up @@ -126,7 +126,7 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
.unwrap();

// Initialize uv-client
let cache = Cache::temp()?.init()?;
let cache = Cache::temp(None)?.init()?;
let mut builder = RegistryClientBuilder::new(cache).markers(&markers);

let linux = Platform::new(
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ mod tests {
}
"##};

let cache = Cache::temp().unwrap().init().unwrap();
let cache = Cache::temp(None).unwrap().init().unwrap();

fs::write(
&mocked_interpreter,
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod tests {

Ok(Self {
tempdir,
cache: Cache::temp()?,
cache: Cache::temp(None)?,
installations: ManagedPythonInstallations::temp()?,
search_path: None,
workdir,
Expand Down
Loading