mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 10:58:28 +00:00
![]() <!-- 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  After: use self build binary  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> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |