uv/crates
Ivan Shcheklein b5ec859273
fix(git): lock cache on resolve (#5051)
Fixes a concurrency issue when multiple processes are installing the
same package in different virtual environments from Git ref (not a
specific Git commit).

## Symptoms

That's how some of symptoms looked like in our case:

```
DEBUG uv 0.2.21
DEBUG Checking for Python interpreter at path `/tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/37bf51bfba4699a940ce31349422b24a5bc55a2b179ed7aec74459a9ae8d57b7/bin/python`
DEBUG Using Python 3.12.4 environment at /tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/37bf51bfba4699a940ce31349422b24a5bc55a2b179ed7aec74459a9ae8d57b7/bin/python
DEBUG Acquired lock for `/tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/37bf51bfba4699a940ce31349422b24a5bc55a2b179ed7aec74459a9ae8d57b7`
DEBUG At least one requirement is not satisfied: torch
DEBUG Using request timeout of 300s
DEBUG Found 37 packages in `--find-links` entry: /tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/.cache/pip/wheels
DEBUG Updating git source `Url { scheme: "https", cannot_be_a_base: false, username: "***", password: None, host: Some(Domain("github.com")), port: None, path: "/iterative/datachain", query: None, fragment: None }`
DEBUG Attempting GitHub fast path for: https://api.github.com/repos/iterative/datachain/commits/fix-distributed-test
DEBUG failed to check github HTTP status client error (404 Not Found) for url (https://api.github.com/repos/iterative/datachain/commits/fix-distributed-test)
DEBUG Performing a Git fetch for: https://***@github.com/iterative/datachain
error: Failed to download and build: `datachain @ git+https://***@github.com/iterative/datachain@fix-distributed-test`
Caused by: Git operation failed
Caused by: process didn't exit successfully: `git clone --local /tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/.cache/uv/git-v0/db/9d45a3e6f56b0a69 /tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/.cache/uv/git-v0/checkouts/9d45a3e6f56b0a69/56b15b8` (exit status: 128)
--- stderr
fatal: destination path '/tmp/pytest-of-runner/pytest-0/tmp_venv_dir/python3.12/.cache/uv/git-v0/checkouts/9d45a3e6f56b0a69/56b15b8' already exists and is not an empty directory.
```

## Cause of the issue

It is the same command that is failing - `git clone`, and I think it's
happening because it was trying to first get the repo to dereference the
`fix-distributed-test` branch:

`Given a remote source distribution, return a precise variant, if
possible.`

And it's happening w/i acquiring a lock around cache.

## Fix

I thinks we can reuse the existing `fetch` method that has already lock
around cache:


https://github.com/astral-sh/uv/pull/5051/files#diff-f58bb99dee2c4922d156ace3e7de651f0d9a81fc8e9447a2ad865de5c53543fcR61-R68

```python
        // Avoid races between different processes, too.
        let lock_dir = cache.join("locks");
        ....
```

## Questions

- Are there any tests that cover concurrency? I'm quite new to Rust and
if someone can point me to some examples and I can create a similar test
or a new one.
- Is error handling done correctly in this PR (again, I'm new to Rust -
I'll review and read about it, but it's better also for someone else to
review this)
2024-07-16 16:06:06 -04:00
..
bench Switch to Current-Thread Tokio Runtime (#4934) 2024-07-09 18:21:16 -04:00
cache-key Cache tool environments in uv tool run (#4784) 2024-07-03 19:25:39 -04:00
distribution-filename Filter out none ABI wheels with mismatched Python versions (#5087) 2024-07-15 21:41:13 -04:00
distribution-types Use lockfile to prefill resolver index (#4495) 2024-07-12 18:49:28 -04:00
install-wheel-rs Lock directories to synchronize wheel-install copies (#4978) 2024-07-12 00:53:20 +00:00
once-map Use lockfile to prefill resolver index (#4495) 2024-07-12 18:49:28 -04:00
pep440-rs pep508: add MarkerTree::negate 2024-07-12 04:37:36 -07:00
pep508-rs uv-resolver: add support for incomplete markers 2024-07-15 10:09:01 -07:00
platform-tags fix: add missing ppc64le alias for powerpc64le (#3963) 2024-06-02 13:15:24 -04:00
pypi-types Respect tool upgrades in uv tool install (#4736) 2024-07-02 16:46:31 -04:00
requirements-txt Preserve verbatim URLs for --find-links (#4838) 2024-07-05 16:57:40 -05:00
uv Allow conflicting locals when forking (#5104) 2024-07-16 16:57:30 +00:00
uv-auth Enable workspace lint configuration in remaining crates (#4329) 2024-06-18 03:02:28 +00:00
uv-build Add a custom error message for --no-build-isolation torch dependencies (#5041) 2024-07-13 21:12:26 +00:00
uv-cache Rename "built-wheels" cache bucket to "source-dists" (#5077) 2024-07-15 14:41:03 -05:00
uv-cli Add a command to append uv's binary directory to PATH (#4975) 2024-07-12 22:09:34 +00:00
uv-client Cache downloaded wheel when range requests aren't supported (#5089) 2024-07-16 09:21:47 -04:00
uv-configuration Add manylinux_2_31 to supported --python-platform (#4965) 2024-07-10 16:30:35 +00:00
uv-dev Fix depth of settings headers (#5103) 2024-07-16 14:00:03 +00:00
uv-dispatch Switch to Current-Thread Tokio Runtime (#4934) 2024-07-09 18:21:16 -04:00
uv-distribution Cache downloaded wheel when range requests aren't supported (#5089) 2024-07-16 09:21:47 -04:00
uv-extract Download wheel to disk when streaming unzip failed with HTTP streaming error (#5094) 2024-07-16 09:00:46 -04:00
uv-fs Replace map_or(false, ..) uses with is_some_and and is_ok_and (#4703) 2024-07-01 19:28:42 +00:00
uv-git fix(git): lock cache on resolve (#5051) 2024-07-16 16:06:06 -04:00
uv-installer Lock directories to synchronize wheel-install copies (#4978) 2024-07-12 00:53:20 +00:00
uv-macros Generate API reference for options documentation (#5072) 2024-07-15 19:48:40 +00:00
uv-normalize uv-resolver: add TRACE dump of resolver output 2024-07-16 09:51:54 -07:00
uv-options-metadata Generate API reference for options documentation (#5072) 2024-07-15 19:48:40 +00:00
uv-python Respect the libc of the execution environment with uv python list (#5036) 2024-07-14 11:14:57 -05:00
uv-requirements Allow constraints to be provided in --upgrade-package (#4952) 2024-07-09 20:09:13 -07:00
uv-resolver Allow conflicting locals when forking (#5104) 2024-07-16 16:57:30 +00:00
uv-scripts Add PEP 723 support to uv run (#4656) 2024-07-01 08:20:24 -04:00
uv-settings Fix depth of settings headers (#5103) 2024-07-16 14:00:03 +00:00
uv-shell Add Windows path updates for uv tool (#5029) 2024-07-13 01:55:05 +00:00
uv-state Cache tool environments in uv tool run (#4784) 2024-07-03 19:25:39 -04:00
uv-tool Remove non-existent feature (#5049) 2024-07-14 19:49:22 -04:00
uv-trampoline Update windows binaries, again (#4864) 2024-07-07 18:58:22 -04:00
uv-types Change "toolchain" to "python" (#4735) 2024-07-03 07:44:29 -05:00
uv-version Bump version to v0.2.25 (#5083) 2024-07-15 22:38:59 +00:00
uv-virtualenv Add pypy executables when calling uv venv (#5047) 2024-07-15 13:28:31 -05:00
uv-warnings Fix a bug where no warning is output when parsing of workspace settings fails. (#4014) 2024-06-04 09:21:19 -04:00
README.md Move shell manipulation into its own crate (#5028) 2024-07-12 21:12:58 -04:00

Crates

bench

Functionality for benchmarking uv.

cache-key

Generic functionality for caching paths, URLs, and other resources across platforms.

distribution-filename

Parse built distribution (wheel) and source distribution (sdist) filenames to extract structured metadata.

distribution-types

Abstractions for representing built distributions (wheels) and source distributions (sdists), and the sources from which they can be downloaded.

install-wheel-rs

Install built distributions (wheels) into a virtual environment.]

once-map

A waitmap-like concurrent hash map for executing tasks exactly once.

pep440-rs

Utilities for interacting with Python version numbers and specifiers.

pep508-rs

Utilities for interacting with PEP 508 dependency specifiers.

platform-host

Functionality for detecting the current platform (operating system, architecture, etc.).

platform-tags

Functionality for parsing and inferring Python platform tags as per PEP 425.

uv

Command-line interface for the uv package manager.

uv-build

A PEP 517-compatible build frontend for uv.

uv-cache

Functionality for caching Python packages and associated metadata.

uv-client

Client for interacting with PyPI-compatible HTTP APIs.

uv-dev

Development utilities for uv.

uv-dispatch

A centralized struct for resolving and building source distributions in isolated environments. Implements the traits defined in uv-types.

uv-distribution

Client for interacting with built distributions (wheels) and source distributions (sdists). Capable of fetching metadata, distribution contents, etc.

uv-extract

Utilities for extracting files from archives.

uv-fs

Utilities for interacting with the filesystem.

uv-git

Functionality for interacting with Git repositories.

uv-installer

Functionality for installing Python packages into a virtual environment.

uv-python

Functionality for detecting and leveraging the current Python interpreter.

uv-normalize

Normalize package and extra names as per Python specifications.

uv-package

Types and functionality for working with Python packages, e.g., parsing wheel files.

uv-requirements

Utilities for reading package requirements from pyproject.toml and requirements.txt files.

uv-resolver

Functionality for resolving Python packages and their dependencies.

uv-shell

Utilities for detecting and manipulating shell environments.

uv-types

Shared traits for uv, to avoid circular dependencies.

pypi-types

General-purpose type definitions for types used in PyPI-compatible APIs.

uv-virtualenv

A venv replacement to create virtual environments in Rust.

uv-warnings

User-facing warnings for uv.

requirements-txt

Functionality for parsing requirements.txt files.