Sync all packages in a virtual workspace (#4636)

## Summary

This PR dodges some of the bigger issues raised by
https://github.com/astral-sh/uv/pull/4554 and
https://github.com/astral-sh/uv/pull/4555 by _not_ changing any of the
bigger semantics around syncing and instead merely changing virtual
workspace roots to sync all packages in the workspace (rather than
erroring due to being unable to find a project).

Closes #4541.
This commit is contained in:
Charlie Marsh 2024-06-29 12:43:59 -04:00 committed by GitHub
parent af9c2e60aa
commit 0bb99952f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 205 additions and 54 deletions

View file

@ -24,6 +24,7 @@ use pep508_rs::{MarkerEnvironment, MarkerTree, VerbatimUrl, VerbatimUrlError};
use platform_tags::{TagCompatibility, TagPriority, Tags};
use pypi_types::{HashDigest, ParsedArchiveUrl, ParsedGitUrl};
use uv_configuration::ExtrasSpecification;
use uv_distribution::VirtualProject;
use uv_git::{GitReference, GitSha, RepositoryReference, ResolvedRepositoryReference};
use uv_normalize::{ExtraName, GroupName, PackageName};
@ -317,36 +318,37 @@ impl Lock {
/// Convert the [`Lock`] to a [`Resolution`] using the given marker environment, tags, and root.
pub fn to_resolution(
&self,
workspace_root: &Path,
project: &VirtualProject,
marker_env: &MarkerEnvironment,
tags: &Tags,
root_name: &PackageName,
extras: &ExtrasSpecification,
dev: &[GroupName],
) -> Result<Resolution, LockError> {
let mut queue: VecDeque<(&Distribution, Option<&ExtraName>)> = VecDeque::new();
let mut seen = FxHashSet::default();
// Add the root distribution to the queue.
let root = self
.find_by_name(root_name)
.expect("found too many distributions matching root")
.expect("could not find root");
// Add the workspace packages to the queue.
for root_name in project.packages() {
let root = self
.find_by_name(root_name)
.expect("found too many distributions matching root")
.expect("could not find root");
// Add the base package.
queue.push_back((root, None));
// Add the base package.
queue.push_back((root, None));
// Add any extras.
match extras {
ExtrasSpecification::None => {}
ExtrasSpecification::All => {
for extra in root.optional_dependencies.keys() {
queue.push_back((root, Some(extra)));
// Add any extras.
match extras {
ExtrasSpecification::None => {}
ExtrasSpecification::All => {
for extra in root.optional_dependencies.keys() {
queue.push_back((root, Some(extra)));
}
}
}
ExtrasSpecification::Some(extras) => {
for extra in extras {
queue.push_back((root, Some(extra)));
ExtrasSpecification::Some(extras) => {
for extra in extras {
queue.push_back((root, Some(extra)));
}
}
}
}
@ -377,7 +379,8 @@ impl Lock {
}
}
let name = dist.id.name.clone();
let resolved_dist = ResolvedDist::Installable(dist.to_dist(workspace_root, tags)?);
let resolved_dist =
ResolvedDist::Installable(dist.to_dist(project.workspace().root(), tags)?);
map.insert(name, resolved_dist);
}
let diagnostics = vec![];