Skip to content

Commit d2e632f

Browse files
committed
Add test to ensure that PEP508 are correctly converted to UV markers.
1 parent 84ec18d commit d2e632f

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

crates/pixi_pypi_spec/src/pep508.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl TryFrom<pep508_rs::Requirement> for PixiPypiSpec {
107107
}
108108
}
109109
}
110-
} else if !req.extras.is_empty() {
110+
} else if !req.extras.is_empty() || !req.marker.is_true() {
111111
PixiPypiSpec::with_extras_and_markers(
112112
PixiPypiSource::Registry {
113113
version: VersionOrStar::Star,

crates/pixi_uv_conversions/src/requirements.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub fn as_uv_req(
220220
.iter()
221221
.map(|e| uv_normalize::ExtraName::from_str(e.as_ref()).expect("conversion failed"))
222222
.collect(),
223-
marker: to_uv_marker_tree(&req.env_markers().clone()).expect("marker conversion failed"),
223+
marker: to_uv_marker_tree(req.env_markers()).expect("marker conversion failed"),
224224
groups: Default::default(),
225225
source,
226226
origin: None,
@@ -309,10 +309,47 @@ pub fn pep508_requirement_to_uv_requirement(
309309

310310
#[cfg(test)]
311311
mod tests {
312+
use pep508_rs::MarkerTree;
312313
use uv_redacted::DisplaySafeUrl;
313314

314315
use super::*;
315316

317+
#[test]
318+
fn test_markers() {
319+
let pypi_req = PixiPypiSpec::with_extras_and_markers(
320+
PixiPypiSource::Registry {
321+
version: VersionOrStar::Star,
322+
index: None,
323+
},
324+
vec![],
325+
MarkerTree::from_str("sys_platform == 'linux'").unwrap(),
326+
);
327+
let uv_req = as_uv_req(&pypi_req, "test", Path::new("")).unwrap();
328+
329+
let expected_uv_source = RequirementSource::Registry {
330+
specifier: VersionSpecifiers::empty(),
331+
index: None,
332+
conflict: None,
333+
};
334+
335+
assert_eq!(
336+
uv_req.source, expected_uv_source,
337+
"Expected {} but got {}",
338+
expected_uv_source, uv_req.source
339+
);
340+
341+
let expected_uv_markers =
342+
uv_pep508::MarkerTree::from_str("sys_platform == 'linux'").unwrap();
343+
344+
assert_eq!(
345+
uv_req.marker,
346+
expected_uv_markers,
347+
"Expected {:?} but got {:?}",
348+
expected_uv_markers.try_to_string(),
349+
uv_req.marker.try_to_string(),
350+
);
351+
}
352+
316353
#[test]
317354
fn test_git_url() {
318355
let pypi_req = PixiPypiSpec::new(PixiPypiSource::Git {

0 commit comments

Comments
 (0)