Sync index format when uv add --index updates an existing index URL#19818
Open
BitWeaverDev wants to merge 1 commit into
Open
Sync index format when uv add --index updates an existing index URL#19818BitWeaverDev wants to merge 1 commit into
uv add --index updates an existing index URL#19818BitWeaverDev wants to merge 1 commit into
Conversation
When `uv add --index <name>=<url>` matches an existing index by name, it overwrites the `url` but previously left the `format` key untouched. An index declared with `format = "flat"` would keep that format after being repointed at a Simple-API URL, silently producing an inconsistent configuration that breaks a subsequent `uv lock`. Track whether the URL actually changes and, when it does, sync the `format` to match the incoming index: write `format = "flat"` for flat indexes, and drop the key entirely for Simple indexes (the default). The format is left alone when the URL is unchanged, so existing entries keep their configuration. Closes astral-sh#19759
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
uv add --index <name>=<url>matches an existing index by name and overwrites itsurl, but it previously left theformatkey in place. An index declared asformat = "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 lockreads the staleformat = "flat"and fails to resolve.Reproduction from #19759:
Changes
In
PyProjectTomlMut::add_index, capture whether the URL is actually changing. When it is, sync theformatto match the incoming index:format = "flat"for flat indexes, andformatkey entirely for Simple indexes (the default).When the URL is unchanged, the existing
formatis 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 staleformatkey.add_index_preserves_format_when_url_unchanged— re-adding the same URL leavesformat = "flat"intact.Closes #19759
I used AI as a coding assistant for this contribution, in accordance with the project's AI Policy.