Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Lock aliased project environments through the same workspace path
  • Loading branch information
charliermarsh committed Oct 13, 2026
commit aab9ceffd954e31b8600d89fef88fdf428e4a16c
5 changes: 4 additions & 1 deletion crates/uv-environment-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,11 @@ pub async fn lock_project_environment(
target: ProjectEnvironmentTarget<'_>,
) -> Result<LockedFile, LockedFileError> {
let install_path = target.install_path();
// The workspace exists even when its environment does not. Resolve aliases before choosing
// the lock so two paths to the same workspace cannot initialize it concurrently.
let workspace_path = install_path.simple_canonicalize()?;
LockedFile::acquire(
std::env::temp_dir().join(format!("uv-{}.lock", cache_digest(&install_path))),
std::env::temp_dir().join(format!("uv-{}.lock", cache_digest(&workspace_path))),
LockedFileMode::Exclusive,
install_path.simplified_display(),
)
Expand Down
14 changes: 9 additions & 5 deletions crates/uv/tests/python/venv.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is good but I think we could have just had a second case rather than re-using the existing one. Testing both has meaning too I think?

Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ async fn create_venv_project_environment_lock() -> Result<()> {
requires-python = ">=3.12"
"#,
)?;
let project_link = context.temp_dir.child("project-link");
uv_fs::create_symlink(context.temp_dir.path(), project_link.path())?;

// Simulate another project command holding the environment lock.
let install_path = dunce::canonicalize(context.temp_dir.path())?;
Expand All @@ -476,18 +478,20 @@ async fn create_venv_project_environment_lock() -> Result<()> {
.await?;
let context = context.with_filtered_path(&lock_path, "PROJECT_ENVIRONMENT_LOCK");

// A pathless invocation from the project root uses the workspace-derived lock, including when
// `UV_PROJECT_ENVIRONMENT` changes the environment path. Lock errors warn and continue.
// A project alias uses the same lock, including when `UV_PROJECT_ENVIRONMENT` changes the
// environment path. Lock errors warn and continue.
uv_snapshot!(context.filters(), context.venv()
.arg("--project")
.arg(project_link.path())
.env(EnvVars::UV_PROJECT_ENVIRONMENT, "foo")
.env(EnvVars::RUST_LOG, "warn")
.env(EnvVars::UV_LOCK_TIMEOUT, "1"), @"
exit_code: 0 (success)
----- stderr -----
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
Creating virtual environment at: foo
WARN Failed to acquire project environment lock: Timeout ([TIME]) when waiting for lock on `[TEMP_DIR]/` at `[PROJECT_ENVIRONMENT_LOCK]/`, is another uv process running? You can set `UV_LOCK_TIMEOUT` to increase the timeout.
Activate with: source foo/[BIN]/activate
Creating virtual environment at: project-link/foo
WARN Failed to acquire project environment lock: Timeout ([TIME]) when waiting for lock on `[TEMP_DIR]/project-link` at `[PROJECT_ENVIRONMENT_LOCK]/`, is another uv process running? You can set `UV_LOCK_TIMEOUT` to increase the timeout.
Activate with: source project-link/foo/[BIN]/activate
");
drop(lock);

Expand Down
⌂ 换网址