Skip to content

Commit

Permalink
Improve self-dependency hint to make shadowing clear (#9716)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Dec 10, 2024
1 parent 4c334e6 commit 6fb0d79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
28 changes: 21 additions & 7 deletions crates/uv-resolver/src/pubgrub/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ impl PubGrubReportFormatter<'_> {
&& workspace_members.contains(package_name)
{
output_hints.insert(PubGrubHint::DependsOnItself {
package: package.clone(),
package: package_name.clone(),
workspace: self.is_workspace() && !self.is_single_project_workspace(),
});
}
}
Expand Down Expand Up @@ -956,9 +957,12 @@ pub(crate) enum PubGrubHint {
workspace: bool,
},
/// A package depends on itself at an incompatible version.
DependsOnItself { package: PubGrubPackage },
DependsOnItself {
package: PackageName,
workspace: bool,
},
/// 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
/// subsequent index was not queried. As such, a compatible version may be available on
/// one of the remaining indexes.
UncheckedIndex {
package: PubGrubPackage,
Expand Down Expand Up @@ -1022,7 +1026,8 @@ enum PubGrubHintCore {
workspace: bool,
},
DependsOnItself {
package: PubGrubPackage,
package: PackageName,
workspace: bool,
},
UncheckedIndex {
package: PubGrubPackage,
Expand Down Expand Up @@ -1088,7 +1093,9 @@ impl From<PubGrubHint> for PubGrubHintCore {
dependency,
workspace,
},
PubGrubHint::DependsOnItself { package } => Self::DependsOnItself { package },
PubGrubHint::DependsOnItself { package, workspace } => {
Self::DependsOnItself { package, workspace }
}
PubGrubHint::UncheckedIndex { package, .. } => Self::UncheckedIndex { package },
PubGrubHint::UnauthorizedIndex { index } => Self::UnauthorizedIndex { index },
PubGrubHint::ForbiddenIndex { index } => Self::ForbiddenIndex { index },
Expand Down Expand Up @@ -1331,13 +1338,20 @@ impl std::fmt::Display for PubGrubHint {
dependency.cyan(),
)
}
Self::DependsOnItself { package } => {
Self::DependsOnItself { package, workspace } => {
let project = if *workspace {
"workspace member"
} else {
"project"
};
write!(
f,
"{}{} The package `{}` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.",
"{}{} The {project} `{}` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `{}`, consider renaming the {project} `{}` to avoid creating a conflict.",
"hint".bold().cyan(),
":".bold(),
package.cyan(),
package.cyan(),
package.cyan(),
)
}
Self::UncheckedIndex {
Expand Down
10 changes: 5 additions & 5 deletions crates/uv/tests/it/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19527,7 +19527,7 @@ fn lock_self_incompatible() -> Result<()> {
× 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 at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);

Ok(())
Expand Down Expand Up @@ -19662,7 +19662,7 @@ fn lock_self_extra_to_same_extra_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
╰─▶ Because project[foo] depends on itself at an incompatible version (project==0.2.0) and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.

hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);

Ok(())
Expand Down Expand Up @@ -19696,7 +19696,7 @@ fn lock_self_extra_to_other_extra_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
╰─▶ Because project[foo] depends on itself at an incompatible version (project==0.2.0) and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.

hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);

Ok(())
Expand Down Expand Up @@ -19831,7 +19831,7 @@ fn lock_self_extra_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
╰─▶ Because project[foo] depends on itself at an incompatible version (project==0.2.0) and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.

hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);

Ok(())
Expand Down Expand Up @@ -19960,7 +19960,7 @@ fn lock_self_marker_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
╰─▶ Because only project{sys_platform == 'win32'}<=0.1 is available and your project depends on itself at an incompatible version (project{sys_platform == 'win32'}>0.1), we can conclude that your project's requirements are unsatisfiable.

hint: The package `project` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);

Ok(())
Expand Down

0 comments on commit 6fb0d79

Please sign in to comment.