uv
f7a4d25c - Sync index format when `uv add --index` updates an existing index URL (#19818)

Commit
31 days ago
Sync index format when `uv add --index` updates an existing index URL (#19818) ## Summary `uv add --index <name>=<url>` matches an existing index by name and overwrites its `url`, but it previously left the `format` key in place. An index declared as `format = "flat"` keeps that format even after being repointed at a Simple-API URL, silently producing an inconsistent configuration. The add itself succeeds (the CLI-supplied index carries the correct Simple format), so the breakage only surfaces later — a subsequent `uv lock` reads the stale `format = "flat"` and fails to resolve. Reproduction from #19759: ```console $ uv init --bare --name test $ cat >> pyproject.toml <<EOF [[tool.uv.index]] name = "index" url = "https://example.com/flat" format = "flat" EOF $ uv add iniconfig --index index=https://pypi.org/simple $ grep -A3 'tool.uv.index' pyproject.toml [[tool.uv.index]] name = "index" url = "https://pypi.org/simple" format = "flat" # <-- stale, breaks `uv lock` ``` ## Changes In `PyProjectTomlMut::add_index`, capture whether the URL is actually changing. When it is, sync the `format` to match the incoming index: - write `format = "flat"` for flat indexes, and - drop the `format` key entirely for Simple indexes (the default). When the URL is unchanged, the existing `format` is left untouched, so entries that aren't being repointed keep their configuration. ## Test Two unit tests in `pyproject_mut.rs`, matching the module's existing test style: - `add_index_clears_format_on_url_update` — repointing a flat index at a Simple URL removes the stale `format` key. - `add_index_preserves_format_when_url_unchanged` — re-adding the same URL leaves `format = "flat"` intact. Closes #19759 --- I used AI as a coding assistant for this contribution, in accordance with the project's [AI Policy](https://github.com/astral-sh/.github/blob/main/AI_POLICY.md). --------- Co-authored-by: BitWeaverDev <hi.bitweaver@gmail.com> Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
Author
Parents
Loading