Use a non-local lock file for locking system interpreters (#2045)

This commit is contained in:
Charlie Marsh 2024-02-28 11:03:02 -05:00 committed by GitHub
parent e91fe1925b
commit ea5ebe59af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -107,7 +107,16 @@ impl PythonEnvironment {
/// Lock the virtual environment to prevent concurrent writes.
pub fn lock(&self) -> Result<LockedFile, std::io::Error> {
LockedFile::acquire(self.root.join(".lock"), self.root.normalized_display())
if self.interpreter.is_virtualenv() {
// If the environment a virtualenv, use a virtualenv-specific lock file.
LockedFile::acquire(self.root.join(".lock"), self.root.normalized_display())
} else {
// Otherwise, use a global lock file.
LockedFile::acquire(
env::temp_dir().join(format!("uv-{}.lock", cache_key::digest(&self.root))),
self.root.normalized_display(),
)
}
}
}