Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve self-dependency hint to make shadowing clear #9716

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -950,9 +951,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 @@ -1016,7 +1020,8 @@ enum PubGrubHintCore {
workspace: bool,
},
DependsOnItself {
package: PubGrubPackage,
package: PackageName,
workspace: bool,
},
UncheckedIndex {
package: PubGrubPackage,
Expand Down Expand Up @@ -1082,7 +1087,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 @@ -1325,13 +1332,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 @@ -19457,7 +19457,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 @@ -19592,7 +19592,7 @@ fn lock_self_extra_to_same_extra_incompatible() -> Result<()> {
× 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 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 @@ -19626,7 +19626,7 @@ fn lock_self_extra_to_other_extra_incompatible() -> Result<()> {
× 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 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 @@ -19761,7 +19761,7 @@ fn lock_self_extra_incompatible() -> Result<()> {
× 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 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 @@ -19890,7 +19890,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 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
Loading