-
Notifications
You must be signed in to change notification settings - Fork 171
fix(conda_types): parse features and license_family in MatchSpec #2175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ritankarsaha
wants to merge
1
commit into
conda:main
Choose a base branch
from
ritankarsaha:fix/matchspec-features-license-family
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -520,8 +520,8 @@ fn parse_bracket_vec_into_components( | |
| return Err(ParseMatchSpecError::InvalidBracketKey("when".to_string())); | ||
| } | ||
| } | ||
| // TODO: Still need to add `features` and `license_family` | ||
| // to the match spec. | ||
| "license_family" => match_spec.license_family = Some(value.to_string()), | ||
| "features" => match_spec.features = Some(value.to_string()), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Features have been deprecated and can be removed here. |
||
| _ => Err(ParseMatchSpecError::InvalidBracketKey(key.to_owned()))?, | ||
| } | ||
| } | ||
|
|
@@ -1610,6 +1610,51 @@ mod tests { | |
| assert_eq!(spec.license, Some("MIT".into())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parsing_license_family() { | ||
| let spec = MatchSpec::from_str("python[license_family=MIT]", Strict).unwrap(); | ||
| assert_eq!(spec.license_family, Some("MIT".into())); | ||
|
|
||
| // Roundtrip: Display -> parse must produce the same spec. | ||
| let reparsed = MatchSpec::from_str(&spec.to_string(), Strict).unwrap(); | ||
| assert_eq!(reparsed.license_family, Some("MIT".into())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parsing_features() { | ||
| let spec = MatchSpec::from_str("numpy[features=blas]", Strict).unwrap(); | ||
| assert_eq!(spec.features, Some("blas".into())); | ||
|
|
||
| // Roundtrip: Display -> parse must produce the same spec. | ||
| let reparsed = MatchSpec::from_str(&spec.to_string(), Strict).unwrap(); | ||
| assert_eq!(reparsed.features, Some("blas".into())); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_features_and_license_family_matching() { | ||
| use crate::{match_spec::Matches, PackageName, PackageRecord, Version}; | ||
|
|
||
| let mut record = PackageRecord::new( | ||
| PackageName::from_str("numpy").unwrap(), | ||
| Version::from_str("1.24.0").unwrap(), | ||
| "py310h1234_0".to_string(), | ||
| ); | ||
| record.features = Some("blas".to_string()); | ||
| record.license_family = Some("MIT".to_string()); | ||
|
|
||
| // Both fields match. | ||
| let spec = MatchSpec::from_str("numpy[license_family=MIT, features=blas]", Strict).unwrap(); | ||
| assert!(spec.matches(&record)); | ||
|
|
||
| // license_family mismatch. | ||
| let spec = MatchSpec::from_str("numpy[license_family=GPL]", Strict).unwrap(); | ||
| assert!(!spec.matches(&record)); | ||
|
|
||
| // features mismatch. | ||
| let spec = MatchSpec::from_str("numpy[features=openblas]", Strict).unwrap(); | ||
| assert!(!spec.matches(&record)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_parsing_track_features() { | ||
| let cases = vec![ | ||
|
|
@@ -1714,6 +1759,8 @@ mod tests { | |
| .unwrap(), | ||
| ), | ||
| license: Some("MIT".into()), | ||
| license_family: Some("MIT".into()), | ||
| features: Some("blas".into()), | ||
| condition: None, | ||
| track_features: None, | ||
| }); | ||
|
|
||
3 changes: 2 additions & 1 deletion
3
...ch_spec/snapshots/rattler_conda_types__match_spec__parse__tests__matchspec_to_string.snap
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,9 @@ | ||
| --- | ||
| source: crates/rattler_conda_types/src/match_spec/parse.rs | ||
| assertion_line: 1770 | ||
| expression: vec_strings | ||
| --- | ||
| [ | ||
| "foo 1.0.*[build_number=\">6\"]", | ||
| "conda-forge/linux-64:foospace:foo 1.0.* py27_0*[md5=\"8b1a9953c4611296a827abf8c47804d7\", sha256=\"315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3\", build_number=\">=6\", fn=\"foo-1.0-py27_0.tar.bz2\", url=\"https://conda.anaconda.org/conda-forge/linux-64/foo-1.0-py27_0.tar.bz2\", license=\"MIT\"]", | ||
| "conda-forge/linux-64:foospace:foo 1.0.* py27_0*[md5=\"8b1a9953c4611296a827abf8c47804d7\", sha256=\"315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3\", build_number=\">=6\", fn=\"foo-1.0-py27_0.tar.bz2\", url=\"https://conda.anaconda.org/conda-forge/linux-64/foo-1.0-py27_0.tar.bz2\", license=\"MIT\", license_family=\"MIT\", features=\"blas\"]", | ||
| ] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Features are not used anymore so this is not needed.