-
Notifications
You must be signed in to change notification settings - Fork 63
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
fix: merge purls from matching records in lock-file #965
Conversation
4770029
to
b42a7cb
Compare
build == &conda_package.record().build | ||
}) && subdir.as_ref().map_or(true, |subdir| { | ||
subdir == &conda_package.record().subdir | ||
all_packages |
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.
small request: could we please add a comment what this part of branching is doing?
|
||
#[test] | ||
fn test_merge_records_and_purls() { | ||
let record = PackageRecord { |
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.
One small suggestion for the test:
maybe we could test here that indeed a package with purl will win in case of merging with one that doesn't have purl.
This is my idea:
|
||
#[test] | ||
fn test_merge_records_and_purls() { | ||
let record = PackageRecord { |
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.
let record = PackageRecord { | |
let mut record = PackageRecord::new( | |
PackageName::new_unchecked("foobar"), | |
Version::from_str("1.0.0").unwrap(), | |
"build".into(), | |
); | |
let mut record_without_purl = PackageRecord::new( | |
PackageName::new_unchecked("foobar"), | |
Version::from_str("1.0.0").unwrap(), | |
"build".into(), | |
); | |
record.purls = Some( | |
vec![ | |
"pkg:pypi/foobar@1.0.0".parse().unwrap(), | |
] | |
.into_iter() | |
.collect(), | |
); | |
let record = PackageRecord { | |
subdir: "linux-64".into(), | |
..record | |
}; | |
let record_without_purl = PackageRecord { | |
subdir: "linux-64".into(), | |
..record_without_purl | |
}; |
crates/rattler_lock/src/builder.rs
Outdated
"foobar", | ||
Platform::Linux64, | ||
CondaBinaryData { | ||
package_record: PackageRecord { |
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.
package_record: PackageRecord { | |
package_record: record_without_purl, |
.into(), | ||
) | ||
.finish(); | ||
insta::assert_snapshot!(lock_file.render_to_string().unwrap()); |
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.
so the snapshot will be like this:
---
source: crates/rattler_lock/src/builder.rs
expression: lock_file.render_to_string().unwrap()
---
version: 6
environments:
default:
channels: []
packages:
linux-64:
- conda: https://prefix.dev/example/linux-64/foobar-1.0.0-build.tar.bz2
foobar:
channels: []
packages:
linux-64:
- conda: https://prefix.dev/example/linux-64/foobar-1.0.0-build.tar.bz2
packages:
- conda: https://prefix.dev/example/linux-64/foobar-1.0.0-build.tar.bz2
arch: x86_64
platform: linux
channel: null
purls:
- pkg:pypi/foobar@1.0.0
which will give us confidence that we indeed merge purls , even when the package is in different environments
@nichmor I added all your feedback, let me know what you think! |
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.
I like it!
Just tested the branch on pixi and it fixes it! Thanks! |
When two packages are added or read from a v5 lock-file they are deduplicated. However, even though the packages may refer to the same package, they might include optional fields like
purls
. This PR merges these optional fields from deduplicated records before building or deserializing lock-files.I added two tests:
I believe this does not need a bump of the lock-file format because this only adds data that was already read correctly but was not properly serialized/constructed.