Skip to content

Commit

Permalink
Default value for conda_packages in repodata.json (#441)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminLowry authored Dec 15, 2023
1 parent 3bedecd commit f3c30ff
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 10 deletions.
27 changes: 21 additions & 6 deletions crates/rattler_conda_types/src/repo_data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ pub struct RepoData {

/// The conda packages contained in the repodata.json file (under a different key for
/// backwards compatibility with previous conda versions)
#[serde(rename = "packages.conda", serialize_with = "sort_map_alphabetically")]
#[serde(
default,
rename = "packages.conda",
serialize_with = "sort_map_alphabetically"
)]
pub conda_packages: FxHashMap<String, PackageRecord>,

/// removed packages (files are still accessible, but they are not installable like regular packages)
Expand Down Expand Up @@ -455,18 +459,22 @@ mod test {

#[test]
fn test_serialize_packages() {
// load test data
let test_data_path =
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../test-data");
let data_path = test_data_path.join("channels/dummy/linux-64/repodata.json");
let repodata = RepoData::from_path(&data_path).unwrap();
let repodata = deserialize_json_from_test_data("channels/dummy/linux-64/repodata.json");
insta::assert_yaml_snapshot!(repodata);

// serialize to json
let json = serde_json::to_string_pretty(&repodata).unwrap();
insta::assert_snapshot!(json);
}

#[test]
fn test_deserialize_no_packages_conda() {
let repodata = deserialize_json_from_test_data(
"channels/dummy-no-conda-packages/linux-64/repodata.json",
);
insta::assert_yaml_snapshot!(repodata);
}

#[test]
fn test_base_url_packages() {
// load test data
Expand Down Expand Up @@ -525,4 +533,11 @@ mod test {
"https://conda.anaconda.org/root/bla.conda"
);
}

fn deserialize_json_from_test_data(path: &str) -> RepoData {
let test_data_path =
std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../../test-data");
let data_path = test_data_path.join(path);
RepoData::from_path(&data_path).unwrap()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
---
source: crates/rattler_conda_types/src/repo_data/mod.rs
assertion_line: 477
expression: repodata
---
info:
subdir: linux-64
base_url: "../linux-64"
packages:
bar-1.0-unix_py36h1af98f8_2.tar.bz2:
build: unix_py36h1af98f8_2
build_number: 1
depends:
- __unix
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: bar
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: 1.2.3
"baz-1.0-unix_py36h1af98f8_2\u0000.tar.bz2":
build: "unix_py36h1af98f8_2\u0000"
build_number: 1
depends:
- __unix
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: baz
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: 1.2.3
"baz-2.0-unix_py36h1af98f8_2\u0000.tar.bz2":
build: "unix_py36h1af98f8_2\u0000"
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: baz
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "2.0"
bors-1.0-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: bors
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "1.0"
bors-1.1-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: bors
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "1.1"
bors-1.2.1-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: bors
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: 1.2.1
bors-2.0-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: bors
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "2.0"
bors-2.1-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: bors
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "2.1"
foo-3.0.2-py36h1af98f8_1.conda:
build: py36h1af98f8_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: fb731d9290f0bcbf3a054665f33ec94f
name: foo
sha256: 67a63bec3fd3205170eaad532d487595b8aaceb9814d13c6858d7bac3ef24cd4
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: 3.0.2
foo-3.0.2-py36h1af98f8_1.tar.bz2:
build: py36h1af98f8_1
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: d65ab674acf3b7294ebacaec05fc5b54
name: foo
sha256: 1154fceeb5c4ee9bb97d245713ac21eb1910237c724d2b7103747215663273c2
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: 3.0.2
foo-4.0.2-py36h1af98f8_2.tar.bz2:
build: py36h1af98f8_2
build_number: 1
depends: []
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: foo
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: 4.0.2
foobar-2.0-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends:
- bors <2.0
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: foobar
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "2.0"
foobar-2.1-bla_1.tar.bz2:
build: bla_1
build_number: 1
depends:
- bors <2.0
license: MIT
license_family: MIT
md5: bc13aa58e2092bcb0b97c561373d3905
name: foobar
sha256: 97ec377d2ad83dfef1194b7aa31b0c9076194e10d995a6e696c9d07dd782b14a
size: 414494
subdir: linux-64
timestamp: 1605110689658
version: "2.1"
packages.conda: {}
repodata_version: 2
11 changes: 7 additions & 4 deletions crates/rattler_repodata_gateway/src/sparse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,17 @@ struct LazyRepoData<'i> {
info: Option<ChannelInfo>,

/// The tar.bz2 packages contained in the repodata.json file
#[serde(borrow)]
#[serde(deserialize_with = "deserialize_filename_and_raw_record")]
#[serde(borrow, deserialize_with = "deserialize_filename_and_raw_record")]
packages: Vec<(PackageFilename<'i>, &'i RawValue)>,

/// The conda packages contained in the repodata.json file (under a different key for
/// backwards compatibility with previous conda versions)
#[serde(borrow, rename = "packages.conda")]
#[serde(deserialize_with = "deserialize_filename_and_raw_record")]
#[serde(
borrow,
default,
deserialize_with = "deserialize_filename_and_raw_record",
rename = "packages.conda"
)]
conda_packages: Vec<(PackageFilename<'i>, &'i RawValue)>,
}

Expand Down
Git LFS file not shown

0 comments on commit f3c30ff

Please sign in to comment.