Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 20fcfae

Browse files
committedNov 28, 2024·
Add disjoint
1 parent be36372 commit 20fcfae

File tree

6 files changed

+198
-43
lines changed

6 files changed

+198
-43
lines changed
 

‎crates/uv-pep508/src/marker/tree.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,9 @@ impl MarkerTree {
745745
/// false negatives, i.e. it may not be able to detect that two markers are disjoint for
746746
/// complex expressions.
747747
pub fn is_disjoint(&self, other: &MarkerTree) -> bool {
748-
INTERNER.lock().is_disjoint(self.0, other.0)
748+
let mutex = &*MUTUAL_EXCLUSIONS;
749+
let node = INTERNER.lock().and(self.0, other.0);
750+
node.is_false() || INTERNER.lock().is_disjoint(node, mutex.0)
749751
}
750752

751753
/// Returns the contents of this marker tree, if it contains at least one expression.
@@ -2697,19 +2699,18 @@ mod test {
26972699

26982700
assert_simplifies(
26992701
"(implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32')",
2700-
"(implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32')",
2702+
"os_name == 'nt' and sys_platform == 'win32'",
27012703
);
27022704

27032705
assert_simplifies(
2704-
"(sys_platform == 'darwin' or sys_platform == 'win32')
2705-
and ((implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32'))",
2706-
"(implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32')",
2706+
"(sys_platform == 'darwin' or sys_platform == 'win32') and ((implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32'))",
2707+
"os_name == 'nt' and sys_platform == 'win32'",
27072708
);
27082709

27092710
assert_simplifies(
27102711
"(sys_platform == 'darwin' or sys_platform == 'win32')
27112712
and ((platform_version != '1' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32'))",
2712-
"(os_name == 'nt' and platform_version != '1' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32')",
2713+
"os_name == 'nt' and sys_platform == 'win32'",
27132714
);
27142715

27152716
assert_simplifies(

‎crates/uv-resolver/src/resolution/output.rs

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ impl ResolverOutput {
151151
// Insert each node only once.
152152
continue;
153153
}
154-
155154
Self::add_edge(&mut graph, &mut inverse, root_index, edge, marker.clone());
156155
}
157156
}

‎crates/uv-resolver/src/resolver/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,11 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
17191719
let mut marker = constraint.marker.clone();
17201720
marker.and(requirement.marker.clone());
17211721

1722+
if marker.is_false() {
1723+
trace!("skipping {constraint} because of disjoint markers: {}", marker.try_to_string().unwrap());
1724+
return None;
1725+
}
1726+
17221727
Cow::Owned(Requirement {
17231728
name: constraint.name.clone(),
17241729
extras: constraint.extras.clone(),
@@ -1734,17 +1739,17 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
17341739
let mut marker = constraint.marker.clone();
17351740
marker.and(requirement.marker.clone());
17361741

1737-
// Additionally, if the requirement is `requests ; sys_platform == 'darwin'`
1738-
// and the constraint is `requests ; python_version == '3.6'`, the
1739-
// constraint should only apply when _both_ markers are true.
17401742
if marker.is_false() {
1741-
trace!("skipping {constraint} because of Requires-Python: {requires_python}");
1743+
trace!("skipping {constraint} because of disjoint markers: {}", marker.try_to_string().unwrap());
17421744
return None;
17431745
}
1746+
1747+
// Additionally, if the requirement is `requests ; sys_platform == 'darwin'`
1748+
// and the constraint is `requests ; python_version == '3.6'`, the
1749+
// constraint should only apply when _both_ markers are true.
17441750
if python_marker.is_disjoint(&marker) {
17451751
trace!(
1746-
"skipping constraint {requirement} because of Requires-Python: {requires_python}",
1747-
requires_python = python_requirement.target(),
1752+
"skipping constraint {requirement} because of Requires-Python: {requires_python}"
17481753
);
17491754
return None;
17501755
}

‎crates/uv/tests/it/export.rs

+165-3
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,169 @@ fn dependency_conflicting_markers() -> Result<()> {
501501
"#,
502502
)?;
503503

504-
context.lock().assert().success();
504+
uv_snapshot!(context.filters(), context.lock(), @r###"
505+
success: true
506+
exit_code: 0
507+
----- stdout -----
508+
509+
----- stderr -----
510+
Resolved 11 packages in [TIME]
511+
"###);
512+
513+
let lock = context.read("uv.lock");
514+
515+
insta::with_settings!(
516+
{
517+
filters => context.filters(),
518+
},
519+
{
520+
insta::assert_snapshot!(
521+
lock, @r###"
522+
version = 1
523+
requires-python = ">=3.12"
524+
resolution-markers = [
525+
"sys_platform == 'darwin'",
526+
"sys_platform == 'win32'",
527+
"sys_platform != 'darwin' and sys_platform != 'win32'",
528+
]
529+
530+
[options]
531+
exclude-newer = "2024-03-25T00:00:00Z"
532+
533+
[[package]]
534+
name = "async-generator"
535+
version = "1.10"
536+
source = { registry = "https://pypi.org/simple" }
537+
sdist = { url = "https://files.pythonhosted.org/packages/ce/b6/6fa6b3b598a03cba5e80f829e0dadbb49d7645f523d209b2fb7ea0bbb02a/async_generator-1.10.tar.gz", hash = "sha256:6ebb3d106c12920aaae42ccb6f787ef5eefdcdd166ea3d628fa8476abe712144", size = 29870 }
538+
wheels = [
539+
{ url = "https://files.pythonhosted.org/packages/71/52/39d20e03abd0ac9159c162ec24b93fbcaa111e8400308f2465432495ca2b/async_generator-1.10-py3-none-any.whl", hash = "sha256:01c7bf666359b4967d2cda0000cc2e4af16a0ae098cbffcb8472fb9e8ad6585b", size = 18857 },
540+
]
541+
542+
[[package]]
543+
name = "attrs"
544+
version = "23.2.0"
545+
source = { registry = "https://pypi.org/simple" }
546+
sdist = { url = "https://files.pythonhosted.org/packages/e3/fc/f800d51204003fa8ae392c4e8278f256206e7a919b708eef054f5f4b650d/attrs-23.2.0.tar.gz", hash = "sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30", size = 780820 }
547+
wheels = [
548+
{ url = "https://files.pythonhosted.org/packages/e0/44/827b2a91a5816512fcaf3cc4ebc465ccd5d598c45cefa6703fcf4a79018f/attrs-23.2.0-py3-none-any.whl", hash = "sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1", size = 60752 },
549+
]
550+
551+
[[package]]
552+
name = "cffi"
553+
version = "1.16.0"
554+
source = { registry = "https://pypi.org/simple" }
555+
dependencies = [
556+
{ name = "pycparser", marker = "sys_platform == 'win32'" },
557+
]
558+
sdist = { url = "https://files.pythonhosted.org/packages/68/ce/95b0bae7968c65473e1298efb042e10cafc7bafc14d9e4f154008241c91d/cffi-1.16.0.tar.gz", hash = "sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0", size = 512873 }
559+
wheels = [
560+
{ url = "https://files.pythonhosted.org/packages/c9/6e/751437067affe7ac0944b1ad4856ec11650da77f0dd8f305fae1117ef7bb/cffi-1.16.0-cp312-cp312-win32.whl", hash = "sha256:b2ca4e77f9f47c55c194982e10f058db063937845bb2b7a86c84a6cfe0aefa8b", size = 173564 },
561+
{ url = "https://files.pythonhosted.org/packages/e9/63/e285470a4880a4f36edabe4810057bd4b562c6ddcc165eacf9c3c7210b40/cffi-1.16.0-cp312-cp312-win_amd64.whl", hash = "sha256:68678abf380b42ce21a5f2abde8efee05c114c2fdb2e9eef2efdb0257fba1235", size = 181956 },
562+
]
563+
564+
[[package]]
565+
name = "idna"
566+
version = "3.6"
567+
source = { registry = "https://pypi.org/simple" }
568+
sdist = { url = "https://files.pythonhosted.org/packages/bf/3f/ea4b9117521a1e9c50344b909be7886dd00a519552724809bb1f486986c2/idna-3.6.tar.gz", hash = "sha256:9ecdbbd083b06798ae1e86adcbfe8ab1479cf864e4ee30fe4e46a003d12491ca", size = 175426 }
569+
wheels = [
570+
{ url = "https://files.pythonhosted.org/packages/c2/e7/a82b05cf63a603df6e68d59ae6a68bf5064484a0718ea5033660af4b54a9/idna-3.6-py3-none-any.whl", hash = "sha256:c05567e9c24a6b9faaa835c4821bad0590fbb9d5779e7caa6e1cc4978e7eb24f", size = 61567 },
571+
]
572+
573+
[[package]]
574+
name = "outcome"
575+
version = "1.3.0.post0"
576+
source = { registry = "https://pypi.org/simple" }
577+
dependencies = [
578+
{ name = "attrs", marker = "sys_platform == 'darwin' or sys_platform == 'win32'" },
579+
]
580+
sdist = { url = "https://files.pythonhosted.org/packages/98/df/77698abfac98571e65ffeb0c1fba8ffd692ab8458d617a0eed7d9a8d38f2/outcome-1.3.0.post0.tar.gz", hash = "sha256:9dcf02e65f2971b80047b377468e72a268e15c0af3cf1238e6ff14f7f91143b8", size = 21060 }
581+
wheels = [
582+
{ url = "https://files.pythonhosted.org/packages/55/8b/5ab7257531a5d830fc8000c476e63c935488d74609b50f9384a643ec0a62/outcome-1.3.0.post0-py2.py3-none-any.whl", hash = "sha256:e771c5ce06d1415e356078d3bdd68523f284b4ce5419828922b6871e65eda82b", size = 10692 },
583+
]
584+
585+
[[package]]
586+
name = "project"
587+
version = "0.1.0"
588+
source = { editable = "." }
589+
dependencies = [
590+
{ name = "trio", version = "0.10.0", source = { registry = "https://pypi.org/simple" }, marker = "sys_platform == 'win32'" },
591+
{ name = "trio", version = "0.25.0", source = { registry = "https://pypi.org/simple" }, marker = "sys_platform == 'darwin'" },
592+
]
593+
594+
[package.metadata]
595+
requires-dist = [
596+
{ name = "trio", marker = "sys_platform == 'darwin'", specifier = "==0.25.0" },
597+
{ name = "trio", marker = "sys_platform == 'win32'", specifier = "==0.10.0" },
598+
]
599+
600+
[[package]]
601+
name = "pycparser"
602+
version = "2.21"
603+
source = { registry = "https://pypi.org/simple" }
604+
sdist = { url = "https://files.pythonhosted.org/packages/5e/0b/95d387f5f4433cb0f53ff7ad859bd2c6051051cebbb564f139a999ab46de/pycparser-2.21.tar.gz", hash = "sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206", size = 170877 }
605+
wheels = [
606+
{ url = "https://files.pythonhosted.org/packages/62/d5/5f610ebe421e85889f2e55e33b7f9a6795bd982198517d912eb1c76e1a53/pycparser-2.21-py2.py3-none-any.whl", hash = "sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9", size = 118697 },
607+
]
608+
609+
[[package]]
610+
name = "sniffio"
611+
version = "1.3.1"
612+
source = { registry = "https://pypi.org/simple" }
613+
sdist = { url = "https://files.pythonhosted.org/packages/a2/87/a6771e1546d97e7e041b6ae58d80074f81b7d5121207425c964ddf5cfdbd/sniffio-1.3.1.tar.gz", hash = "sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc", size = 20372 }
614+
wheels = [
615+
{ url = "https://files.pythonhosted.org/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl", hash = "sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2", size = 10235 },
616+
]
617+
618+
[[package]]
619+
name = "sortedcontainers"
620+
version = "2.4.0"
621+
source = { registry = "https://pypi.org/simple" }
622+
sdist = { url = "https://files.pythonhosted.org/packages/e8/c4/ba2f8066cceb6f23394729afe52f3bf7adec04bf9ed2c820b39e19299111/sortedcontainers-2.4.0.tar.gz", hash = "sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88", size = 30594 }
623+
wheels = [
624+
{ url = "https://files.pythonhosted.org/packages/32/46/9cb0e58b2deb7f82b84065f37f3bffeb12413f947f9388e4cac22c4621ce/sortedcontainers-2.4.0-py2.py3-none-any.whl", hash = "sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0", size = 29575 },
625+
]
626+
627+
[[package]]
628+
name = "trio"
629+
version = "0.10.0"
630+
source = { registry = "https://pypi.org/simple" }
631+
resolution-markers = [
632+
"sys_platform == 'win32'",
633+
]
634+
dependencies = [
635+
{ name = "async-generator", marker = "sys_platform == 'win32'" },
636+
{ name = "attrs", marker = "sys_platform == 'win32'" },
637+
{ name = "cffi", marker = "os_name == 'nt' and sys_platform == 'win32'" },
638+
{ name = "idna", marker = "sys_platform == 'win32'" },
639+
{ name = "outcome", marker = "sys_platform == 'win32'" },
640+
{ name = "sniffio", marker = "sys_platform == 'win32'" },
641+
{ name = "sortedcontainers", marker = "sys_platform == 'win32'" },
642+
]
643+
sdist = { url = "https://files.pythonhosted.org/packages/e6/20/37be7b5f47db6a9fbf905b5de5386e5b7193c45d07becb750db6f03cd117/trio-0.10.0.tar.gz", hash = "sha256:d323cc15f6406d15954af91e5e34af2001cc24163fdde29e3f88a227a1b53ab0", size = 402511 }
644+
645+
[[package]]
646+
name = "trio"
647+
version = "0.25.0"
648+
source = { registry = "https://pypi.org/simple" }
649+
resolution-markers = [
650+
"sys_platform == 'darwin'",
651+
]
652+
dependencies = [
653+
{ name = "attrs", marker = "sys_platform == 'darwin'" },
654+
{ name = "idna", marker = "sys_platform == 'darwin'" },
655+
{ name = "outcome", marker = "sys_platform == 'darwin'" },
656+
{ name = "sniffio", marker = "sys_platform == 'darwin'" },
657+
{ name = "sortedcontainers", marker = "sys_platform == 'darwin'" },
658+
]
659+
sdist = { url = "https://files.pythonhosted.org/packages/b4/51/4f5ae37ec58768b9c30e5bc5b89431a7baf3fa9d0dda98983af6ef55eb47/trio-0.25.0.tar.gz", hash = "sha256:9b41f5993ad2c0e5f62d0acca320ec657fdb6b2a2c22b8c7aed6caf154475c4e", size = 551863 }
660+
wheels = [
661+
{ url = "https://files.pythonhosted.org/packages/17/c9/f86f89f14d52f9f2f652ce24cb2f60141a51d087db1563f3fba94ba07346/trio-0.25.0-py3-none-any.whl", hash = "sha256:e6458efe29cc543e557a91e614e2b51710eba2961669329ce9c862d50c6e8e81", size = 467161 },
662+
]
663+
"###
664+
);
665+
}
666+
);
505667

506668
uv_snapshot!(context.filters(), context.export(), @r###"
507669
success: true
@@ -516,7 +678,7 @@ fn dependency_conflicting_markers() -> Result<()> {
516678
attrs==23.2.0 ; sys_platform == 'darwin' or sys_platform == 'win32' \
517679
--hash=sha256:935dc3b529c262f6cf76e50877d35a4bd3c1de194fd41f47a2b7ae8f19971f30 \
518680
--hash=sha256:99b87a485a5820b23b879f04c2305b44b951b502fd64be915879d77a7e8fc6f1
519-
cffi==1.16.0 ; (implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32') \
681+
cffi==1.16.0 ; os_name == 'nt' and sys_platform == 'win32' \
520682
--hash=sha256:68678abf380b42ce21a5f2abde8efee05c114c2fdb2e9eef2efdb0257fba1235 \
521683
--hash=sha256:b2ca4e77f9f47c55c194982e10f058db063937845bb2b7a86c84a6cfe0aefa8b \
522684
--hash=sha256:bcb3ef43e58665bbda2fb198698fcae6776483e0c4a631aa5647806c25e02cc0
@@ -526,7 +688,7 @@ fn dependency_conflicting_markers() -> Result<()> {
526688
outcome==1.3.0.post0 ; sys_platform == 'darwin' or sys_platform == 'win32' \
527689
--hash=sha256:9dcf02e65f2971b80047b377468e72a268e15c0af3cf1238e6ff14f7f91143b8 \
528690
--hash=sha256:e771c5ce06d1415e356078d3bdd68523f284b4ce5419828922b6871e65eda82b
529-
pycparser==2.21 ; (implementation_name != 'pypy' and os_name == 'nt' and sys_platform == 'darwin') or (os_name == 'nt' and sys_platform == 'win32') \
691+
pycparser==2.21 ; os_name == 'nt' and sys_platform == 'win32' \
530692
--hash=sha256:8ee45429555515e1f6b185e78100aea234072576aa43ab53aefcae078162fca9 \
531693
--hash=sha256:e644fdec12f7872f86c58ff790da456218b10f863970249516d60a5eaca77206
532694
sniffio==1.3.1 ; sys_platform == 'darwin' or sys_platform == 'win32' \

0 commit comments

Comments
 (0)
Please sign in to comment.