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

DRAFT: Add warning for packages without lower bound with --resolution=lowest #2

Closed
wants to merge 7 commits into from
Closed
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
29 changes: 27 additions & 2 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use uv_distribution::{ArchiveMetadata, DistributionDatabase};
use uv_git::GitResolver;
use uv_normalize::{ExtraName, PackageName};
use uv_types::{BuildContext, HashStrategy, InstalledPackagesProvider};
use uv_warnings::warn_user_once;

use crate::candidate_selector::{CandidateDist, CandidateSelector};
use crate::dependency_provider::UvDependencyProvider;
Expand All @@ -46,6 +47,7 @@ use crate::pubgrub::{
};
use crate::python_requirement::PythonRequirement;
use crate::resolution::ResolutionGraph;
use crate::resolution_mode::ResolutionStrategy;
pub(crate) use crate::resolver::availability::{
IncompletePackage, ResolverVersion, UnavailablePackage, UnavailableReason, UnavailableVersion,
};
Expand Down Expand Up @@ -854,7 +856,13 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
) -> Result<Vec<Dependencies>, ResolveError> {
type Dep = (PubGrubPackage, Range<Version>);

let result = self.get_dependencies(package, version, priorities, request_sink);
let result = self.get_dependencies(
package,
version,
priorities,
request_sink,
self.selector.resolution_strategy(),
);
if self.markers.is_some() {
return result.map(|deps| vec![deps]);
}
Expand Down Expand Up @@ -912,6 +920,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
version: &Version,
priorities: &mut PubGrubPriorities,
request_sink: &Sender<Request>,
resolution_strategy: &ResolutionStrategy,
) -> Result<Dependencies, ResolveError> {
match &**package {
PubGrubPackageInner::Root(_) => {
Expand Down Expand Up @@ -940,6 +949,14 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
for (package, version) in dependencies.iter() {
debug!("Adding direct dependency: {package}{version}");

// Warn the user if the direct dependency is not pinned.
if matches!(
resolution_strategy,
ResolutionStrategy::Lowest | ResolutionStrategy::LowestDirect(..)
) && *version == (Range::full())
{
warn_user_once!("The direct dependency `{package}` is unpinned. Consider setting a lower bound.");
}
// Update the package priorities.
priorities.insert(package, version);

Expand Down Expand Up @@ -1075,6 +1092,14 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
for (dep_package, dep_version) in dependencies.iter() {
debug!("Adding transitive dependency for {package}=={version}: {dep_package}{dep_version}");

// Warn the user if the transitive dependency is not pinned.
if matches!(
resolution_strategy,
ResolutionStrategy::Lowest | ResolutionStrategy::LowestDirect(..)
) && *dep_version == (Range::full())
{
warn_user_once!("The transitive dependency `{dep_package}` is unpinned. Consider setting a lower bound.");
}
// Update the package priorities.
priorities.insert(dep_package, dep_version);

Expand Down Expand Up @@ -1575,7 +1600,7 @@ impl<'a> From<ResolvedDistRef<'a>> for Request {
// N.B. This is almost identical to `ResolvedDistRef::to_owned`, but
// creates a `Request` instead of a `ResolvedDist`. There's probably
// some room for DRYing this up a bit. The obvious way would be to
// add a method to create a `Dist`, but a `Dist` cannot reprented an
// add a method to create a `Dist`, but a `Dist` cannot represented an
// installed dist.
match dist {
ResolvedDistRef::InstallableRegistrySourceDist { sdist, prioritized } => {
Expand Down
Loading