From 967f136564372b699b140cf21d3bfac6855cbfe6 Mon Sep 17 00:00:00 2001 From: Eric Mark Martin Date: Tue, 25 Jun 2024 06:47:52 -0400 Subject: [PATCH] More precise locking with --prefix option (#4506) ## Summary In #4085, support was implemented for the `--prefix` option. When using this option, however, a lock is either acquired on the virtualenv or globally, preventing multiple installs to different `--prefix`s from the same interpreter. In this change, acquire the lock on just the prefix in question. ## Test Plan Ran a `uv pip install` with `--prefix` and `RUST_LOG=trace` and observed that the lock was acquired in the prefix. --- crates/uv-toolchain/src/environment.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/uv-toolchain/src/environment.rs b/crates/uv-toolchain/src/environment.rs index 9d0dfb471..8830f5b25 100644 --- a/crates/uv-toolchain/src/environment.rs +++ b/crates/uv-toolchain/src/environment.rs @@ -160,6 +160,9 @@ impl PythonEnvironment { if let Some(target) = self.0.interpreter.target() { // If we're installing into a `--target`, use a target-specific lock file. LockedFile::acquire(target.root().join(".lock"), target.root().user_display()) + } else if let Some(prefix) = self.0.interpreter.prefix() { + // Likewise, if we're installing into a `--prefix`, use a prefix-specific lock file. + LockedFile::acquire(prefix.root().join(".lock"), prefix.root().user_display()) } else if self.0.interpreter.is_virtualenv() { // If the environment a virtualenv, use a virtualenv-specific lock file. LockedFile::acquire(self.0.root.join(".lock"), self.0.root.user_display())