Skip to content

Commit dce7a5b

Browse files
authored
feat: implement v3 repodata/matchspec support in pixi spec (#6015)
1 parent e0bf96c commit dce7a5b

46 files changed

Lines changed: 2685 additions & 93 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pixi_build_backend/src/dependencies.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ fn convert_nameless_matchspec(spec: NamelessMatchSpec) -> pbt::BinaryPackageSpec
175175
sha256: spec.sha256,
176176
url: spec.url,
177177
license: spec.license,
178+
condition: spec.condition,
178179
}
179180
}
180181

crates/pixi_build_backend/src/specs_conversion.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ fn binary_package_spec_to_package_dependency(
226226
sha256,
227227
url,
228228
license,
229+
condition,
229230
} = binary_spec;
230231

231232
// If the version is "*" and no other constraints are present, treat it as None
@@ -247,8 +248,9 @@ fn binary_package_spec_to_package_dependency(
247248
&sha256,
248249
&url,
249250
&license,
251+
&condition,
250252
) {
251-
(None, None, None, None, None, None, None, None, None) => {
253+
(None, None, None, None, None, None, None, None, None, None) => {
252254
version.filter(|v| v != &rattler_conda_types::VersionSpec::Any)
253255
}
254256
_ => Some(version.unwrap_or(rattler_conda_types::VersionSpec::Any)),
@@ -268,7 +270,7 @@ fn binary_package_spec_to_package_dependency(
268270
sha256,
269271
url,
270272
license,
271-
condition: None,
273+
condition,
272274
track_features: None,
273275
flags: None,
274276
license_family: None,
@@ -492,6 +494,30 @@ mod test {
492494
assert_eq!(match_spec.to_string(), "python");
493495
}
494496

497+
#[test]
498+
fn test_binary_package_conversion_preserves_condition() {
499+
use rattler_conda_types::{MatchSpecCondition, ParseMatchSpecOptions, RepodataRevision};
500+
501+
let name = PackageName::new_unchecked("numpy");
502+
let condition = MatchSpecCondition::MatchSpec(Box::new(
503+
MatchSpec::from_str(
504+
"python >=3.10",
505+
ParseMatchSpecOptions::lenient().with_repodata_revision(RepodataRevision::V3),
506+
)
507+
.unwrap(),
508+
));
509+
let spec = BinaryPackageSpec {
510+
version: Some("*".parse().unwrap()),
511+
condition: Some(condition.clone()),
512+
..BinaryPackageSpec::default()
513+
};
514+
let match_spec = binary_package_spec_to_package_dependency(name, spec);
515+
let PackageDependency::Binary(match_spec) = match_spec else {
516+
panic!("expected binary dependency");
517+
};
518+
assert_eq!(match_spec.condition, Some(condition));
519+
}
520+
495521
/// Regression test for <https://github.com/prefix-dev/pixi/issues/4526>:
496522
/// `version = "*"` combined with a `build` constraint must preserve both
497523
/// fields so the resulting `MatchSpec` round-trips correctly through its

crates/pixi_build_backend/src/traits/package_spec.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl PackageSpec for pbt::PackageSpec {
6363
sha256,
6464
url,
6565
license,
66+
condition,
6667
} = spec;
6768

6869
version == &Some(rattler_conda_types::VersionSpec::Any)
@@ -75,6 +76,7 @@ impl PackageSpec for pbt::PackageSpec {
7576
&& sha256.is_none()
7677
&& url.is_none()
7778
&& license.is_none()
79+
&& condition.is_none()
7880
}
7981
_ => false,
8082
}
@@ -131,7 +133,7 @@ impl BinarySpecExt for pbt::BinaryPackageSpec {
131133
license: self.license.clone(),
132134
extras: None,
133135
namespace: None,
134-
condition: None,
136+
condition: self.condition.clone(),
135137
track_features: None,
136138
flags: None,
137139
license_family: None,
@@ -166,6 +168,7 @@ mod tests {
166168
sha256: None,
167169
url: None,
168170
license: None,
171+
condition: None,
169172
};
170173

171174
let package_spec = pbt::PackageSpec::Binary(binary_spec);
@@ -199,6 +202,7 @@ mod tests {
199202
sha256: None,
200203
url: None,
201204
license: None,
205+
condition: None,
202206
};
203207

204208
let package_spec = pbt::PackageSpec::Binary(binary_spec);
@@ -230,6 +234,7 @@ mod tests {
230234
sha256: None,
231235
url: None,
232236
license: None,
237+
condition: None,
233238
};
234239

235240
let package_spec = pbt::PackageSpec::Binary(binary_spec);

crates/pixi_build_backend/src/variants.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn can_be_used_as_variant(spec: &pbt::PackageSpec) -> bool {
2121
sha256,
2222
url,
2323
license,
24+
condition,
2425
} = spec;
2526

2627
version == &Some(VersionSpec::Any)
@@ -33,6 +34,7 @@ pub fn can_be_used_as_variant(spec: &pbt::PackageSpec) -> bool {
3334
&& sha256.is_none()
3435
&& url.is_none()
3536
&& license.is_none()
37+
&& condition.is_none()
3638
}
3739
_ => false,
3840
}

crates/pixi_build_backend/tests/integration/common/model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ fn convert_package_spec_to_v1(spec: &PackageSpec) -> PbtPackageSpec {
218218
sha256: None,
219219
url: None,
220220
license: None,
221+
condition: None,
221222
})
222223
}
223224
PackageSpec::Source(source_spec) => {

crates/pixi_build_backend_passthrough/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ fn is_star_requirement(spec: &PackageSpec) -> bool {
423423
sha256: None,
424424
url: None,
425425
license: None,
426+
condition: None,
426427
} => version
427428
.as_ref()
428429
.is_none_or(|v| matches!(v, VersionSpec::Any)),

crates/pixi_build_type_conversions/src/project_model.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ fn to_pixi_spec_v1(
3131
build,
3232
build_number,
3333
extras: None,
34+
flags: None,
3435
subdir,
3536
namespace: None,
3637
license,
38+
license_family: None,
3739
condition: None,
40+
track_features: None,
3841
} = source
3942
else {
4043
unimplemented!(
@@ -103,7 +106,7 @@ fn to_pixi_spec_v1(
103106
// These are currently explicitly ignored in the conversion
104107
namespace: _,
105108
extras: _,
106-
condition: _,
109+
condition,
107110
track_features: _,
108111
flags: _,
109112
license_family: _,
@@ -119,6 +122,7 @@ fn to_pixi_spec_v1(
119122
sha256,
120123
url,
121124
license,
125+
condition,
122126
})
123127
}
124128
};

crates/pixi_build_type_conversions/src/snapshots/pixi_build_type_conversions__project_model__tests__conversions_v1_docs@cpp.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/pixi_build_type_conversions/src/project_model.rs
3+
assertion_line: 300
34
expression: project_model
45
---
56
{
@@ -29,7 +30,8 @@ expression: project_model
2930
"md5": null,
3031
"sha256": null,
3132
"url": null,
32-
"license": null
33+
"license": null,
34+
"condition": null
3335
}
3436
},
3537
"nanobind": {
@@ -43,7 +45,8 @@ expression: project_model
4345
"md5": null,
4446
"sha256": null,
4547
"url": null,
46-
"license": null
48+
"license": null,
49+
"condition": null
4750
}
4851
},
4952
"python": {
@@ -57,7 +60,8 @@ expression: project_model
5760
"md5": null,
5861
"sha256": null,
5962
"url": null,
60-
"license": null
63+
"license": null,
64+
"condition": null
6165
}
6266
}
6367
},

crates/pixi_build_type_conversions/src/snapshots/pixi_build_type_conversions__project_model__tests__conversions_v1_docs@dev.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
source: crates/pixi_build_type_conversions/src/project_model.rs
3+
assertion_line: 300
34
expression: project_model
45
---
56
{
@@ -29,7 +30,8 @@ expression: project_model
2930
"md5": null,
3031
"sha256": null,
3132
"url": null,
32-
"license": null
33+
"license": null,
34+
"condition": null
3335
}
3436
}
3537
},
@@ -45,7 +47,8 @@ expression: project_model
4547
"md5": null,
4648
"sha256": null,
4749
"url": null,
48-
"license": null
50+
"license": null,
51+
"condition": null
4952
}
5053
}
5154
},
@@ -61,7 +64,8 @@ expression: project_model
6164
"md5": null,
6265
"sha256": null,
6366
"url": null,
64-
"license": null
67+
"license": null,
68+
"condition": null
6569
}
6670
}
6771
},

0 commit comments

Comments
 (0)