uv/crates
KATO So ad86005e9a
Warn when duplicate index names found in single file (#11824)
<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:
- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->
## Summary

This pull request introduces validation for unique index names in the
`tool.uv.index` field and adds corresponding tests to ensure the
functionality. The most important changes include adding a custom
deserializer function, updating the `ToolUv` struct to use the new
deserializer, and adding tests to verify the behavior.

Validation and deserialization:

*
[`crates/uv-workspace/src/pyproject.rs`](diffhunk://#diff-e12cd255985adfd45ab06f398cb420d2f543841ccbeea4175ccf827aa9215b9dR283-R311):
Added a custom deserializer function `deserialize_index_vec` to validate
that index names in the `tool.uv.index` field are unique.
*
[`crates/uv-workspace/src/pyproject.rs`](diffhunk://#diff-e12cd255985adfd45ab06f398cb420d2f543841ccbeea4175ccf827aa9215b9dR374):
Updated the `ToolUv` struct to use the `deserialize_index_vec` function
for the `index` field.

Testing:

*
[`crates/uv/tests/it/lock.rs`](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15336):
Added a test `lock_repeat_named_index` to verify that duplicate index
names result in an error.
[[1]](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15336)
[[2]](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15360-R15402)
*
[`crates/uv/tests/it/lock.rs`](diffhunk://#diff-82edd36151736f44055f699a34c8b19a63ffc4cf3c86bf5fb34d69f8ac88a957R15360-R15402):
Added a test `lock_unique_named_index` to verify that unique index names
result in successful lock file generation.

Schema update:

*
[`uv.schema.json`](diffhunk://#diff-c669473b258a19ba6d3557d0369126773b68b27171989f265333a77bc5cb935bR205):
Updated the schema to set the default value of the `index` field to
`null`.

Fixes #11804

## Test Plan
### Steps to reproduce and verify the fix:

1. Clone the repository and checkout the feature branch
   ```bash
   git clone https://github.com/astral-sh/uv.git
   cd uv
   git checkout feature/warn-duplicate-index-names
   ```

2. Build the modified binary
   ```bash
   cargo build
   ```

3. Create a test project using the system installed uv
   ```bash
   uv init uv-test
   cd uv-test
   ```

4. Manually edit pyproject.toml to add duplicate index names
   ```toml
   [[tool.uv.index]]
   name = "alpha_b"
   url = "<omitted>"

   [[tool.uv.index]]
   name = "alpha_b"
   url = "<omitted>"
   ```

5. Try to add a package using the modified binary
   ```bash
   ../target/debug/uv add numpy
   ```

### Results
Before: use release binary
![スクリーンショット 2025-02-27 15 52
28](https://github.com/user-attachments/assets/2823a4b4-b3ba-40aa-aa41-e593d35c3f3b)

After: use self build binary
![スクリーンショット 2025-02-27 15 51
58](https://github.com/user-attachments/assets/9ac773a9-58cd-4d4b-8685-148bf6dc85fb)

Now when attempting to use a pyproject.toml with duplicate index names,
the modified binary correctly detects the issue and produces an error
message:
```
error: Failed to parse: `pyproject.toml`
  Caused by: TOML parse error at line 9, column 1
  |
9 | [[tool.uv.index]]
  | ^^^^^^^^^^^^^^^^^
duplicate index name `alpha_b`
```

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2025-02-27 21:33:57 +00:00
..
uv Warn when duplicate index names found in single file (#11824) 2025-02-27 21:33:57 +00:00
uv-auth Migrate from urlencoding to percent-encoding (#11144) 2025-01-31 16:29:46 -05:00
uv-bench Remove warnings for missing lower bounds (#11195) 2025-02-03 16:03:31 -06:00
uv-build-backend Remove unused thiserror variants (#11713) 2025-02-22 12:12:22 -10:00
uv-build-frontend Remove unused thiserror variants (#11713) 2025-02-22 12:12:22 -10:00
uv-cache Use hash instead of full wheel name in wheels bucket (#11738) 2025-02-26 22:41:57 +00:00
uv-cache-info Fix git-tag cache-key reader in case of slashes (#10467) (#10500) 2025-01-11 21:30:46 -05:00
uv-cache-key Use hash instead of full wheel name in wheels bucket (#11738) 2025-02-26 22:41:57 +00:00
uv-cli Upgrade Rust toolchain to 1.85 (#11720) 2025-02-23 16:52:34 +01:00
uv-client Use hash instead of full wheel name in wheels bucket (#11738) 2025-02-26 22:41:57 +00:00
uv-configuration Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-console Don't panic on Ctrl-C in confirm prompt (#11706) 2025-02-26 11:10:04 +01:00
uv-dev Add anchor links to arguments and options in the CLI reference (#11754) 2025-02-24 15:48:14 -06:00
uv-dirs Eliminate dependencies on directores and dirs-sys (#8048) 2024-11-07 14:29:54 -06:00
uv-dispatch Add uv sync --dry-run (#11299) 2025-02-06 23:52:49 +00:00
uv-distribution Use hash instead of full wheel name in wheels bucket (#11738) 2025-02-26 22:41:57 +00:00
uv-distribution-filename Fix version string truncation while generating cache_key (#11830) 2025-02-27 08:48:43 -05:00
uv-distribution-types Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-extract Use SmallString on Hashes (#11756) 2025-02-24 10:32:00 -10:00
uv-fs Remove TODO around atomic writes (#11710) 2025-02-22 12:12:12 -10:00
uv-git Move GIT_TERMINAL_PROMPT to env vars (#11789) 2025-02-26 03:56:24 +00:00
uv-git-types Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-globfilter Build backend: Revamp include/exclude (#9525) 2024-12-01 11:32:35 +00:00
uv-install-wheel Remove unused thiserror variants (#11713) 2025-02-22 12:12:22 -10:00
uv-installer Use hash instead of full wheel name in wheels bucket (#11738) 2025-02-26 22:41:57 +00:00
uv-macros Remove unnecessary prefixes (#10158) 2024-12-25 14:18:01 -05:00
uv-metadata chore: Move all integration tests to a single binary (#8093) 2024-10-11 16:41:35 +02:00
uv-normalize Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-once-map Use shared resolver state between add and lock (#8146) 2024-10-12 14:58:07 +00:00
uv-options-metadata Upgrade minimum Rust version to 1.83 (#9815) 2024-12-11 10:06:19 -06:00
uv-pep440 Avoid redundant clones in version containment check (#11767) 2025-02-25 14:36:22 +00:00
uv-pep508 Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-performance-flate2-backend Re-enable zlib-ng on all platforms (except s390x, PowerPC, and FreeBSD) (#10370) 2025-01-07 13:04:34 -05:00
uv-performance-memory-allocator Run cargo update (#10173) 2024-12-26 12:00:58 -05:00
uv-platform-tags Allow installation of manylinux wheels on loongarch64 (#10927) 2025-01-24 14:36:03 +01:00
uv-publish Use SmallString on Hashes (#11756) 2025-02-24 10:32:00 -10:00
uv-pypi-types Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-python Update windows registry to 0.5 (#11799) 2025-02-26 16:33:31 +01:00
uv-requirements Don't panic on Ctrl-C in confirm prompt (#11706) 2025-02-26 11:10:04 +01:00
uv-requirements-txt Skip unquote allocation for non-quoted strings (#11813) 2025-02-26 21:56:31 +00:00
uv-resolver Always store registry index on resolution packages (#11815) 2025-02-27 02:46:37 +00:00
uv-scripts Add tool.uv.build-constraint-dependencies to pyproject.toml (#11585) 2025-02-17 20:58:36 -05:00
uv-settings Fix missing a closing bracket in the cache-keys setting (#11669) 2025-02-20 20:16:19 +00:00
uv-shell Remove the winreg crate (#11805) 2025-02-26 18:56:15 +01:00
uv-small-str Avoid using owned String in deserializers (#11764) 2025-02-25 14:28:16 +00:00
uv-state Add uv-dirs to consolidate directory lookup methods (#8453) 2024-10-22 11:33:25 -05:00
uv-static Move GIT_TERMINAL_PROMPT to env vars (#11789) 2025-02-26 03:56:24 +00:00
uv-tool Remove unused thiserror variants (#11713) 2025-02-22 12:12:22 -10:00
uv-trampoline Upgrade Rust toolchain to 1.85 (#11720) 2025-02-23 16:52:34 +01:00
uv-trampoline-builder Upgrade Rust toolchain to 1.84.0 (#10533) 2025-01-11 22:19:33 -05:00
uv-types Use boxed slices for hash vector (#11714) 2025-02-24 11:11:44 -06:00
uv-version Bump version to 0.6.3 (#11759) 2025-02-24 17:25:01 -05:00
uv-virtualenv Update code page to 65001 before setting environment variables, fix #11828 (#11831) 2025-02-27 16:14:34 -05:00
uv-warnings chore: Move all integration tests to a single binary (#8093) 2024-10-11 16:41:35 +02:00
uv-workspace Warn when duplicate index names found in single file (#11824) 2025-02-27 21:33:57 +00:00
README.md Link to Dependency specifiers instead of PEP 508 (#8411) 2024-10-21 14:43:38 -04:00

Crates

uv-bench

Functionality for benchmarking uv.

uv-cache-key

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

uv-distribution-filename

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

uv-distribution-types

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

uv-install-wheel-rs

Install built distributions (wheels) into a virtual environment.

uv-once-map

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

uv-pep440-rs

Utilities for interacting with Python version numbers and specifiers.

uv-pep508-rs

Utilities for parsing and evaluating dependency specifiers, previously known as PEP 508.

uv-platform-tags

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

uv-cli

Command-line interface for the uv package manager.

uv-build-frontend

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-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.

uv-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.

uv-workspace

Workspace abstractions for uv.

uv-requirements-txt

Functionality for parsing requirements.txt files.