Skip to content

Commit

Permalink
fix: normalize channel in lock file (#871)
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra authored Sep 23, 2024
1 parent e6c662e commit b12f664
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/rattler_lock/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ mod test {
#[case::v4_pypi_absolute_path("v4/absolute-path-lock.yml")]
#[case::v5_pypi_flat_index("v5/flat-index-lock.yml")]
#[case::v6_conda_source_path("v6/conda-path-lock.yml")]
#[case::v6_derived_channel("v6/derived-channel-lock.yml")]
fn test_parse(#[case] file_name: &str) {
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../test-data/conda-lock")
Expand Down
20 changes: 19 additions & 1 deletion crates/rattler_lock/src/parse/models/v6/conda_package_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ impl<'a> From<&'a CondaPackageData> for CondaPackageDataModel<'a> {
let arch = value.package_record.arch.clone().or(derived_arch);
let platform = value.package_record.platform.clone().or(derived_platform);

let normalized_channel = value
.channel
.as_ref()
.map(strip_trailing_slash)
.map(Cow::into_owned);

Self {
location: value.location.clone(),
name: (Some(package_record.name.as_source())
Expand All @@ -232,7 +238,8 @@ impl<'a> From<&'a CondaPackageData> for CondaPackageDataModel<'a> {
.then_some(Cow::Borrowed(&package_record.subdir)),
noarch: (package_record.noarch != derived_noarch)
.then_some(Cow::Borrowed(&package_record.noarch)),
channel: (value.channel != derived.channel).then_some(Cow::Borrowed(&value.channel)),
channel: (normalized_channel != derived.channel)
.then_some(Cow::Owned(normalized_channel)),
file_name: (value.file_name.as_deref() != derived.file_name.as_deref())
.then_some(Cow::Borrowed(&value.file_name)),
purls: Cow::Borrowed(&value.package_record.purls),
Expand All @@ -257,3 +264,14 @@ impl<'a> From<&'a CondaPackageData> for CondaPackageDataModel<'a> {
}
}
}

fn strip_trailing_slash(url: &Url) -> Cow<'_, Url> {
let path = url.path();
if !path.ends_with("/") {
Cow::Borrowed(url)
} else {
let mut updated_url = url.clone();
updated_url.set_path(path.trim_end_matches('/'));
Cow::Owned(updated_url)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
source: crates/rattler_lock/src/lib.rs
expression: conda_lock
---
version: 6
environments:
default:
channels:
- url: "https://conda.anaconda.org/conda-forge/"
packages:
win-64:
- conda: "https://conda.anaconda.org/conda-forge/win-64/python-3.12.0-h2628c8c_0_cpython.conda"
- conda: child-package
packages:
- conda: child-package
name: child-package
version: 0.1.0
build: pyhbf21a9e_0
subdir: noarch
depends:
- python
input:
hash: b67010bf5bc5608db89c0399e726852b07a7ef4fb26b3aa18171f1d0f6a19c89
globs:
- pixi.toml
- conda: "https://conda.anaconda.org/conda-forge/win-64/python-3.12.0-h2628c8c_0_cpython.conda"
sha256: 90553586879bf328f2f9efb8d8faa958ecba822faf379f0a20c3461467b9b955
md5: defd5d375853a2caff36a19d2d81a28e
license: Python-2.0
size: 16140836
timestamp: 1696321871976
30 changes: 30 additions & 0 deletions test-data/conda-lock/v6/derived-channel-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 6
environments:
default:
channels:
- url: https://conda.anaconda.org/conda-forge/
packages:
win-64:
- conda: https://conda.anaconda.org/conda-forge/win-64/python-3.12.0-h2628c8c_0_cpython.conda
- conda: child-package
packages:
- conda: child-package
name: child-package
version: 0.1.0
build: pyhbf21a9e_0
subdir: noarch
depends:
- python
input:
hash: b67010bf5bc5608db89c0399e726852b07a7ef4fb26b3aa18171f1d0f6a19c89
globs:
- pixi.toml
- conda: https://conda.anaconda.org/conda-forge/win-64/python-3.12.0-h2628c8c_0_cpython.conda
sha256: 90553586879bf328f2f9efb8d8faa958ecba822faf379f0a20c3461467b9b955
md5: defd5d375853a2caff36a19d2d81a28e
arch: x86_64
platform: win
channel: https://conda.anaconda.org/conda-forge/
license: Python-2.0
size: 16140836
timestamp: 1696321871976

0 comments on commit b12f664

Please sign in to comment.