-
Notifications
You must be signed in to change notification settings - Fork 970
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move installable targets out of
uv-resolver
crate (#10126)
## Summary The proximate motivation is that I want to add new variant for scripts, but `uv-resolver` can't depend on `uv-scripts` without creating a circular dependency. However, I think this _does_ just make more sense -- the resolver crate shouldn't be coupled to the various kinds of workspaces, and these details are mostly encoded in `projects/lock.rs` and similar files.
- Loading branch information
1 parent
6745a8b
commit 7c47a45
Showing
11 changed files
with
116 additions
and
84 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use std::path::Path; | ||
|
||
use itertools::Either; | ||
|
||
use uv_normalize::PackageName; | ||
use uv_resolver::{Installable, Lock, Package}; | ||
use uv_workspace::Workspace; | ||
|
||
/// A target that can be installed from a lockfile. | ||
#[derive(Debug, Copy, Clone)] | ||
pub(crate) enum InstallTarget<'lock> { | ||
/// A project (which could be a workspace root or member). | ||
Project { | ||
workspace: &'lock Workspace, | ||
name: &'lock PackageName, | ||
lock: &'lock Lock, | ||
}, | ||
/// An entire workspace. | ||
Workspace { | ||
workspace: &'lock Workspace, | ||
lock: &'lock Lock, | ||
}, | ||
/// An entire workspace with a (legacy) non-project root. | ||
NonProjectWorkspace { | ||
workspace: &'lock Workspace, | ||
lock: &'lock Lock, | ||
}, | ||
} | ||
|
||
impl<'lock> Installable<'lock> for InstallTarget<'lock> { | ||
fn install_path(&self) -> &'lock Path { | ||
match self { | ||
Self::Project { workspace, .. } => workspace.install_path(), | ||
Self::Workspace { workspace, .. } => workspace.install_path(), | ||
Self::NonProjectWorkspace { workspace, .. } => workspace.install_path(), | ||
} | ||
} | ||
|
||
fn lock(&self) -> &'lock Lock { | ||
match self { | ||
Self::Project { lock, .. } => lock, | ||
Self::Workspace { lock, .. } => lock, | ||
Self::NonProjectWorkspace { lock, .. } => lock, | ||
} | ||
} | ||
|
||
fn roots(&self) -> impl Iterator<Item = &PackageName> { | ||
match self { | ||
Self::Project { name, .. } => Either::Right(Either::Left(std::iter::once(*name))), | ||
Self::NonProjectWorkspace { lock, .. } => Either::Left(lock.members().iter()), | ||
Self::Workspace { lock, .. } => { | ||
// Identify the workspace members. | ||
// | ||
// The members are encoded directly in the lockfile, unless the workspace contains a | ||
// single member at the root, in which case, we identify it by its source. | ||
if lock.members().is_empty() { | ||
Either::Right(Either::Right(lock.root().into_iter().map(Package::name))) | ||
} else { | ||
Either::Left(lock.members().iter()) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn project_name(&self) -> Option<&PackageName> { | ||
match self { | ||
Self::Project { name, .. } => Some(name), | ||
Self::Workspace { .. } => None, | ||
Self::NonProjectWorkspace { .. } => None, | ||
} | ||
} | ||
} | ||
|
||
impl<'lock> InstallTarget<'lock> { | ||
/// Return the [`Workspace`] of the target. | ||
pub(crate) fn workspace(&self) -> &'lock Workspace { | ||
match self { | ||
Self::Project { workspace, .. } => workspace, | ||
Self::Workspace { workspace, .. } => workspace, | ||
Self::NonProjectWorkspace { workspace, .. } => workspace, | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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