Compare virtual members when invalidating lockfile (#6754)

## Summary

Whether a package is itself virtual isn't captured in the package
metadata, so we have to compare the sources.

Closes https://github.com/astral-sh/uv/issues/6749.
This commit is contained in:
Charlie Marsh 2024-08-28 11:11:16 -04:00 committed by GitHub
parent 1309f24c43
commit 6a8da7dff8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 295 additions and 1 deletions

View file

@ -751,6 +751,22 @@ impl Lock {
}
}
// Validate that the member sources have not changed (e.g., switched from packaged to
// virtual).
{
for (name, member) in workspace.packages() {
let expected = !member.pyproject_toml().is_package();
let actual = self
.find_by_name(name)
.ok()
.flatten()
.map(|package| matches!(package.id.source, Source::Virtual(_)));
if actual.map_or(true, |actual| actual != expected) {
return Ok(SatisfiesResult::MismatchedSources(name.clone(), expected));
}
}
}
// Validate that the lockfile was generated with the same requirements.
{
let expected: BTreeSet<_> = requirements
@ -1030,6 +1046,8 @@ pub enum SatisfiesResult<'lock> {
Satisfied,
/// The lockfile uses a different set of workspace members.
MismatchedMembers(BTreeSet<PackageName>, &'lock BTreeSet<PackageName>),
/// The lockfile uses a different set of sources for its workspace members.
MismatchedSources(PackageName, bool),
/// The lockfile uses a different set of requirements.
MismatchedRequirements(BTreeSet<Requirement>, BTreeSet<Requirement>),
/// The lockfile uses a different set of constraints.