From decf6cd711fbe9d8729adbfdb8e87025c8726d62 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sat, 7 Dec 2024 14:16:37 -0500 Subject: [PATCH] Add hints --- crates/uv-resolver/src/pubgrub/report.rs | 25 ++++++++++++++++++++++++ crates/uv/tests/it/lock.rs | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/crates/uv-resolver/src/pubgrub/report.rs b/crates/uv-resolver/src/pubgrub/report.rs index 723690cc66d6..7e773c2cefbd 100644 --- a/crates/uv-resolver/src/pubgrub/report.rs +++ b/crates/uv-resolver/src/pubgrub/report.rs @@ -610,6 +610,16 @@ impl PubGrubReportFormatter<'_> { workspace: self.is_workspace() && !self.is_single_project_workspace(), }); } + + if package_name == dependency_name + && (dependency.extra().is_none() || package.extra() == dependency.extra()) + && (dependency.dev().is_none() || dependency.dev() == package.dev()) + && workspace_members.contains(package_name) + { + output_hints.insert(PubGrubHint::DependsOnItself { + package: package.clone(), + }); + } } // Check for no versions due to `Requires-Python`. if matches!( @@ -939,6 +949,8 @@ pub(crate) enum PubGrubHint { dependency: PubGrubPackage, workspace: bool, }, + /// A package depends on itself at an incompatible version. + DependsOnItself { package: PubGrubPackage }, /// A package was available on an index, but not at the correct version, and at least one /// subsequent index was not queried. As such, a compatible version may be available on an /// one of the remaining indexes. @@ -1003,6 +1015,9 @@ enum PubGrubHintCore { dependency: PubGrubPackage, workspace: bool, }, + DependsOnItself { + package: PubGrubPackage, + }, UncheckedIndex { package: PubGrubPackage, }, @@ -1067,6 +1082,7 @@ impl From for PubGrubHintCore { dependency, workspace, }, + PubGrubHint::DependsOnItself { package } => Self::DependsOnItself { package }, PubGrubHint::UncheckedIndex { package, .. } => Self::UncheckedIndex { package }, PubGrubHint::UnauthorizedIndex { index } => Self::UnauthorizedIndex { index }, PubGrubHint::ForbiddenIndex { index } => Self::ForbiddenIndex { index }, @@ -1309,6 +1325,15 @@ impl std::fmt::Display for PubGrubHint { dependency.cyan(), ) } + Self::DependsOnItself { package } => { + write!( + f, + "{}{} The package `{}` depends on itself. This is likely a mistake. Consider removing the dependency.", + "hint".bold().cyan(), + ":".bold(), + package.cyan(), + ) + } Self::UncheckedIndex { package, range, diff --git a/crates/uv/tests/it/lock.rs b/crates/uv/tests/it/lock.rs index 8d7ca9fbe826..a93a3779f40e 100644 --- a/crates/uv/tests/it/lock.rs +++ b/crates/uv/tests/it/lock.rs @@ -19253,6 +19253,8 @@ fn lock_self_incompatible() -> Result<()> { ----- stderr ----- × No solution found when resolving dependencies: ╰─▶ Because your project depends on itself at an incompatible version (project==0.2.0), we can conclude that your project's requirements are unsatisfiable. + + hint: The package `project` depends on itself. This is likely a mistake. Consider removing the dependency. "###); Ok(()) @@ -19391,6 +19393,8 @@ fn lock_self_extra_incompatible() -> Result<()> { ----- stderr ----- × No solution found when resolving dependencies: ╰─▶ Because project[foo] depends on your project and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable. + + hint: The package `project[foo]` depends on itself. This is likely a mistake. Consider removing the dependency. "###); Ok(()) @@ -19519,6 +19523,8 @@ fn lock_self_marker_incompatible() -> Result<()> { ----- stderr ----- × No solution found when resolving dependencies: ╰─▶ Because only project{sys_platform == 'win32'}<=0.1 is available and your project depends on project{sys_platform == 'win32'}>0.1, we can conclude that your project's requirements are unsatisfiable. + + hint: The package `project` depends on itself. This is likely a mistake. Consider removing the dependency. "###); Ok(())