Colocate Python install cache with destination directory (#6043)

## Summary

Closes https://github.com/astral-sh/uv/issues/6036.
This commit is contained in:
Charlie Marsh 2024-08-12 16:15:30 -04:00 committed by GitHub
parent e27a1fce60
commit ae7a8d7f33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 27 additions and 19 deletions

View file

@ -95,6 +95,11 @@ impl ManagedPythonInstallations {
))
}
/// Return the location of the cache directory for managed Python installations.
pub fn cache(&self) -> PathBuf {
self.root.join(".cache")
}
/// Initialize the Python installation directory.
///
/// Ensures the directory is created.
@ -119,6 +124,10 @@ impl ManagedPythonInstallations {
// Create the directory, if it doesn't exist.
fs::create_dir_all(root)?;
// Create the cache directory, if it doesn't exist.
let cache = self.cache();
fs::create_dir_all(&cache)?;
// Add a .gitignore.
match fs::OpenOptions::new()
.write(true)
@ -166,8 +175,10 @@ impl ManagedPythonInstallations {
})
}
};
let cache = self.cache();
Ok(dirs
.into_iter()
.filter(|path| *path != cache)
.filter_map(|path| {
ManagedPythonInstallation::new(path)
.inspect_err(|err| {