Skip to content

Commit 4283b10

Browse files
committed
wip: ci smoke test - rework detection logic
1 parent 8297ce8 commit 4283b10

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

crates/uv-resolver/src/pubgrub/report.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::borrow::Cow;
1+
use std::borrow::{Borrow, Cow};
22
use std::cmp::Ordering;
33
use std::collections::{BTreeMap, BTreeSet};
44
use std::ops::Bound;
@@ -538,14 +538,6 @@ impl PubGrubReportFormatter<'_> {
538538
incomplete_packages,
539539
output_hints,
540540
);
541-
542-
// Check for no versions on the local packages themself, which may
543-
// happen if by mistake one of them is shadowing a transitive dependency.
544-
if workspace_members.contains(name) {
545-
output_hints.insert(PubGrubHint::WorkspacePackageNoVersions {
546-
package: package.clone(),
547-
});
548-
}
549541
}
550542
}
551543
DerivationTree::External(External::FromDependencyOf(
@@ -570,6 +562,7 @@ impl PubGrubReportFormatter<'_> {
570562
}
571563
DerivationTree::External(External::NotRoot(..)) => {}
572564
DerivationTree::Derived(derived) => {
565+
self.local_cycle_hint(workspace_members, derived, output_hints);
573566
self.generate_hints(
574567
&derived.cause1,
575568
selector,
@@ -731,6 +724,44 @@ impl PubGrubReportFormatter<'_> {
731724
}
732725
}
733726
}
727+
728+
/// Try to detect and warn if there is a cycle which involves a local package.
729+
///
730+
/// This shouldn't usually happen, but it could be the symptom of a naming
731+
/// conflict with a transitive dependency existing on the index.
732+
fn local_cycle_hint(
733+
&self,
734+
workspace_members: &BTreeSet<PackageName>,
735+
derived: &Derived<PubGrubPackage, Range<Version>, UnavailableReason>,
736+
output_hints: &mut IndexSet<PubGrubHint>,
737+
) {
738+
for local_package in workspace_members {
739+
let pkg = PubGrubPackage::from_package(local_package.clone(), None, None.into());
740+
if derived.terms.contains_key(&pkg) {
741+
let DerivationTree::External(External::FromDependencyOf(src1, _, dst1, _)) =
742+
derived.cause1.borrow()
743+
else {
744+
continue;
745+
};
746+
747+
let DerivationTree::External(External::FromDependencyOf(src2, _, dst2, _)) =
748+
derived.cause2.borrow()
749+
else {
750+
continue;
751+
};
752+
753+
let cycle_edge_first =
754+
src1.name_no_root().is_some() && src1.name_no_root() == dst2.name_no_root();
755+
let cycle_edge_second =
756+
dst1.name_no_root().is_some() && dst1.name_no_root() == src2.name_no_root();
757+
if cycle_edge_first && cycle_edge_second {
758+
output_hints.insert(PubGrubHint::WorkspacePackageNoVersions {
759+
package: pkg.clone(),
760+
});
761+
}
762+
}
763+
}
764+
}
734765
}
735766

736767
#[derive(Debug, Clone)]

crates/uv/tests/edit.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4821,35 +4821,20 @@ fn add_error_local_cycle() -> Result<()> {
48214821
version = "0.1.0"
48224822
requires-python = ">=3.12"
48234823
dependencies = []
4824-
4825-
[build-system]
4826-
requires = ["setuptools>=42"]
4827-
build-backend = "setuptools.build_meta"
48284824
"#})?;
48294825

4830-
uv_snapshot!(context.filters(), context.add().arg("dagster-webserver==1.8.7"), @r###"
4826+
uv_snapshot!(context.filters(), context.add().arg("dagster-webserver==1.6.13"), @r###"
48314827
success: false
48324828
exit_code: 1
48334829
----- stdout -----
48344830
48354831
----- stderr -----
48364832
× No solution found when resolving dependencies:
4837-
╰─▶ Because there is no version of dagster-webserver==1.8.7 and your project depends on dagster-webserver==1.8.7, we can conclude that your project's requirements are unsatisfiable.
4833+
╰─▶ Because dagster-webserver==1.6.13 depends on your project and your project depends on dagster-webserver==1.6.13, we can conclude that your project's requirements are unsatisfiable.
48384834
48394835
hint: Resolution failed on a dependency ('dagster') which has the same name as your local package ('dagster'). Consider checking your project for possible name conflicts with packages in the index.
48404836
help: If this is intentional, run `uv add --frozen` to skip the lock and sync steps.
48414837
"###);
48424838

4843-
uv_snapshot!(context.filters(), context.add().arg("xyz").arg("--frozen"), @r###"
4844-
success: true
4845-
exit_code: 0
4846-
----- stdout -----
4847-
4848-
----- stderr -----
4849-
"###);
4850-
4851-
let lock = context.temp_dir.join("uv.lock");
4852-
assert!(!lock.exists());
4853-
48544839
Ok(())
48554840
}

0 commit comments

Comments
 (0)