mirror of https://github.com/astral-sh/uv
Fix handling of `extra != ...` markers
This commit is contained in:
parent
caac4814df
commit
73a5822101
|
|
@ -2531,6 +2531,42 @@ mod test {
|
||||||
assert_eq!(simplified, expected);
|
assert_eq!(simplified, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_simplify_extras_with_all_true() {
|
||||||
|
// Test `simplify_extras_with(|_| true)` which is used in `PubGrubPackage::from_package`.
|
||||||
|
// This simulates treating all extras as present/enabled.
|
||||||
|
|
||||||
|
// `extra == 'foo'` with all extras present should simplify to TRUE
|
||||||
|
let markers = MarkerTree::from_str(r#"extra == "foo""#).unwrap();
|
||||||
|
let simplified = markers.simplify_extras_with(|_| true);
|
||||||
|
assert_eq!(simplified, MarkerTree::TRUE);
|
||||||
|
|
||||||
|
// `extra != 'foo'` with all extras present should simplify to FALSE
|
||||||
|
// because the extra IS present, so `!= 'foo'` is false.
|
||||||
|
let markers = MarkerTree::from_str(r#"extra != "foo""#).unwrap();
|
||||||
|
let simplified = markers.simplify_extras_with(|_| true);
|
||||||
|
assert_eq!(simplified, MarkerTree::FALSE);
|
||||||
|
|
||||||
|
// `os_name == "nt" and extra != "foo"` with all extras present
|
||||||
|
// should simplify to FALSE (because `extra != "foo"` is false)
|
||||||
|
let markers = MarkerTree::from_str(r#"os_name == "nt" and extra != "foo""#).unwrap();
|
||||||
|
let simplified = markers.simplify_extras_with(|_| true);
|
||||||
|
assert_eq!(simplified, MarkerTree::FALSE);
|
||||||
|
|
||||||
|
// Compare with `without_extras` which removes extras without evaluating them:
|
||||||
|
// `extra != 'foo'` with `without_extras` should simplify to TRUE
|
||||||
|
let markers = MarkerTree::from_str(r#"extra != "foo""#).unwrap();
|
||||||
|
let simplified = markers.without_extras();
|
||||||
|
assert_eq!(simplified, MarkerTree::TRUE);
|
||||||
|
|
||||||
|
// `os_name == "nt" and extra != "foo"` with `without_extras`
|
||||||
|
// should simplify to `os_name == "nt"`
|
||||||
|
let markers = MarkerTree::from_str(r#"os_name == "nt" and extra != "foo""#).unwrap();
|
||||||
|
let simplified = markers.without_extras();
|
||||||
|
let expected = MarkerTree::from_str(r#"os_name == "nt""#).unwrap();
|
||||||
|
assert_eq!(simplified, expected);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_marker_simplification() {
|
fn test_marker_simplification() {
|
||||||
assert_false("python_version == '3.9.1'");
|
assert_false("python_version == '3.9.1'");
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ impl PubGrubPackage {
|
||||||
// extras end up having two distinct marker expressions, which in turn
|
// extras end up having two distinct marker expressions, which in turn
|
||||||
// makes them two distinct packages. This results in PubGrub being
|
// makes them two distinct packages. This results in PubGrub being
|
||||||
// unable to unify version constraints across such packages.
|
// unable to unify version constraints across such packages.
|
||||||
let marker = marker.simplify_extras_with(|_| true);
|
let marker = marker.without_extras();
|
||||||
if let Some(extra) = extra {
|
if let Some(extra) = extra {
|
||||||
Self(Arc::new(PubGrubPackageInner::Extra {
|
Self(Arc::new(PubGrubPackageInner::Extra {
|
||||||
name,
|
name,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue