-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow user to constrain supported lock environments (#6210)
## Summary The strategy here is: if the user provides supported environments, we use those as the initial forks when resolving. As a result, we never add or explore branches that are disjoint with the supported environments. (If the supported environments change, we ignore the lockfile entirely, so we don't have to worry about any interactions between supported environments and the preference forks.) Closes #6184.
- Loading branch information
1 parent
d02c202
commit 3395d24
Showing
28 changed files
with
790 additions
and
49 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
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
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,78 @@ | ||
use std::str::FromStr; | ||
|
||
use serde::ser::SerializeSeq; | ||
|
||
use pep508_rs::MarkerTree; | ||
|
||
#[derive(Debug, Default, Clone, Eq, PartialEq)] | ||
pub struct SupportedEnvironments(Vec<MarkerTree>); | ||
|
||
impl SupportedEnvironments { | ||
/// Return the list of marker trees. | ||
pub fn as_markers(&self) -> &[MarkerTree] { | ||
&self.0 | ||
} | ||
|
||
/// Convert the [`SupportedEnvironments`] struct into a list of marker trees. | ||
pub fn into_markers(self) -> Vec<MarkerTree> { | ||
self.0 | ||
} | ||
} | ||
|
||
/// Serialize a [`SupportedEnvironments`] struct into a list of marker strings. | ||
impl serde::Serialize for SupportedEnvironments { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let mut seq = serializer.serialize_seq(Some(self.0.len()))?; | ||
for element in &self.0 { | ||
if let Some(contents) = element.contents() { | ||
seq.serialize_element(&contents)?; | ||
} | ||
} | ||
seq.end() | ||
} | ||
} | ||
|
||
/// Deserialize a marker string or list of marker strings into a [`SupportedEnvironments`] struct. | ||
impl<'de> serde::Deserialize<'de> for SupportedEnvironments { | ||
fn deserialize<D>(deserializer: D) -> Result<SupportedEnvironments, D::Error> | ||
where | ||
D: serde::Deserializer<'de>, | ||
{ | ||
struct StringOrVecVisitor; | ||
|
||
impl<'de> serde::de::Visitor<'de> for StringOrVecVisitor { | ||
type Value = SupportedEnvironments; | ||
|
||
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
formatter.write_str("a string or a list of strings") | ||
} | ||
|
||
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> | ||
where | ||
E: serde::de::Error, | ||
{ | ||
let marker = MarkerTree::from_str(value).map_err(serde::de::Error::custom)?; | ||
Ok(SupportedEnvironments(vec![marker])) | ||
} | ||
|
||
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error> | ||
where | ||
A: serde::de::SeqAccess<'de>, | ||
{ | ||
let mut markers = Vec::new(); | ||
|
||
while let Some(elem) = seq.next_element::<String>()? { | ||
let marker = MarkerTree::from_str(&elem).map_err(serde::de::Error::custom)?; | ||
markers.push(marker); | ||
} | ||
|
||
Ok(SupportedEnvironments(markers)) | ||
} | ||
} | ||
|
||
deserializer.deserialize_any(StringOrVecVisitor) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
pub use environments::SupportedEnvironments; | ||
pub use workspace::{ | ||
check_nested_workspaces, DiscoveryOptions, ProjectWorkspace, VirtualProject, Workspace, | ||
WorkspaceError, WorkspaceMember, | ||
}; | ||
|
||
mod environments; | ||
pub mod pyproject; | ||
pub mod pyproject_mut; | ||
mod 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
Oops, something went wrong.