Apply advisory locks when building source distributions (#3525)

## Summary

I don't love this, but it turns out that setuptools is not robust to
parallel builds: https://github.com/pypa/setuptools/issues/3119. As a
result, if you run uv from multiple processes, and they each attempt to
build the same source distribution, you can hit failures.

This PR applies an advisory lock to the source distribution directory.
We apply it unconditionally, even if we ultimately find something in the
cache and _don't_ do a build, which helps ensure that we only build the
distribution once (and wait for that build to complete) rather than
kicking off builds from each thread.

Closes https://github.com/astral-sh/uv/issues/3512.

## Test Plan

Ran:

```sh
#!/bin/bash
make_venv(){
    target/debug/uv venv $1
    source $1/bin/activate
    target/debug/uv pip install opentracing --no-deps --verbose
}

for i in {1..8}
do
   make_venv ./$1/$i &
done
```
This commit is contained in:
Charlie Marsh 2024-05-13 10:42:20 -04:00 committed by GitHub
parent 42c3bfa351
commit 9a92a3ad37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 50 additions and 26 deletions

View file

@ -11,6 +11,7 @@ use rustc_hash::FxHashSet;
use tempfile::{tempdir, TempDir};
use tracing::debug;
pub use archive::ArchiveId;
use distribution_types::InstalledDist;
use pypi_types::Metadata23;
use uv_fs::{cachedir, directories};
@ -23,7 +24,6 @@ use crate::removal::{rm_rf, Removal};
pub use crate::timestamp::Timestamp;
pub use crate::wheel::WheelCache;
use crate::wheel::WheelCacheKind;
pub use archive::ArchiveId;
mod archive;
mod by_timestamp;