Skip to content

Commit

Permalink
wip: ci smoke test - rework detection logic
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Sep 18, 2024
1 parent 8297ce8 commit 4283b10
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
49 changes: 40 additions & 9 deletions crates/uv-resolver/src/pubgrub/report.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use std::borrow::{Borrow, Cow};
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};
use std::ops::Bound;
Expand Down Expand Up @@ -538,14 +538,6 @@ impl PubGrubReportFormatter<'_> {
incomplete_packages,
output_hints,
);

// Check for no versions on the local packages themself, which may
// happen if by mistake one of them is shadowing a transitive dependency.
if workspace_members.contains(name) {
output_hints.insert(PubGrubHint::WorkspacePackageNoVersions {
package: package.clone(),
});
}
}
}
DerivationTree::External(External::FromDependencyOf(
Expand All @@ -570,6 +562,7 @@ impl PubGrubReportFormatter<'_> {
}
DerivationTree::External(External::NotRoot(..)) => {}
DerivationTree::Derived(derived) => {
self.local_cycle_hint(workspace_members, derived, output_hints);
self.generate_hints(
&derived.cause1,
selector,
Expand Down Expand Up @@ -731,6 +724,44 @@ impl PubGrubReportFormatter<'_> {
}
}
}

/// Try to detect and warn if there is a cycle which involves a local package.
///
/// This shouldn't usually happen, but it could be the symptom of a naming
/// conflict with a transitive dependency existing on the index.
fn local_cycle_hint(
&self,
workspace_members: &BTreeSet<PackageName>,
derived: &Derived<PubGrubPackage, Range<Version>, UnavailableReason>,
output_hints: &mut IndexSet<PubGrubHint>,
) {
for local_package in workspace_members {
let pkg = PubGrubPackage::from_package(local_package.clone(), None, None.into());
if derived.terms.contains_key(&pkg) {
let DerivationTree::External(External::FromDependencyOf(src1, _, dst1, _)) =
derived.cause1.borrow()
else {
continue;
};

let DerivationTree::External(External::FromDependencyOf(src2, _, dst2, _)) =
derived.cause2.borrow()
else {
continue;
};

let cycle_edge_first =
src1.name_no_root().is_some() && src1.name_no_root() == dst2.name_no_root();
let cycle_edge_second =
dst1.name_no_root().is_some() && dst1.name_no_root() == src2.name_no_root();
if cycle_edge_first && cycle_edge_second {
output_hints.insert(PubGrubHint::WorkspacePackageNoVersions {
package: pkg.clone(),
});
}
}
}
}
}

#[derive(Debug, Clone)]
Expand Down
19 changes: 2 additions & 17 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4821,35 +4821,20 @@ fn add_error_local_cycle() -> Result<()> {
version = "0.1.0"
requires-python = ">=3.12"
dependencies = []
[build-system]
requires = ["setuptools>=42"]
build-backend = "setuptools.build_meta"
"#})?;

uv_snapshot!(context.filters(), context.add().arg("dagster-webserver==1.8.7"), @r###"
uv_snapshot!(context.filters(), context.add().arg("dagster-webserver==1.6.13"), @r###"
success: false
exit_code: 1
----- stdout -----
----- stderr -----
× No solution found when resolving dependencies:
╰─▶ 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.
╰─▶ 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.
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.
help: If this is intentional, run `uv add --frozen` to skip the lock and sync steps.
"###);

uv_snapshot!(context.filters(), context.add().arg("xyz").arg("--frozen"), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
"###);

let lock = context.temp_dir.join("uv.lock");
assert!(!lock.exists());

Ok(())
}

0 comments on commit 4283b10

Please sign in to comment.