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

Add user warning for packages without lower bound with --resolution=lowest or lowest-direct #4006

1 change: 1 addition & 0 deletions _typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extend-ignore-re = [
"FrIeNdLy-\\._\\.-bArD",
"I borken you cache",
"eb1ba5f5",
"github_pat_.*"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to add this otherwise the pre-commit hook would think Nd should be And in pip_install.rs

]

[default.extend-identifiers]
Expand Down
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 @@ -32,6 +32,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 @@ -45,6 +46,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 @@ -848,7 +850,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 @@ -906,6 +914,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 @@ -934,6 +943,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 @@ -1069,6 +1086,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 @@ -1569,7 +1594,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
6 changes: 6 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,7 @@ fn compile_sdist_resolution_lowest() -> Result<()> {
# via anyio

----- stderr -----
warning: The direct dependency `anyio` is unpinned. Consider setting a lower bound.
Resolved 3 packages in [TIME]
"###
);
Expand Down Expand Up @@ -6597,6 +6598,8 @@ fn editable_direct_dependency() -> Result<()> {
# via setuptools-editable

----- stderr -----
warning: The direct dependency `setuptools-editable` is unpinned. Consider setting a lower bound.
warning: The transitive dependency `iniconfig` is unpinned. Consider setting a lower bound.
Resolved 2 packages in [TIME]
"###);

Expand Down Expand Up @@ -6944,6 +6947,8 @@ dev = ["setuptools"]
# via example

----- stderr -----
warning: The direct dependency `example` is unpinned. Consider setting a lower bound.
warning: The transitive dependency `setuptools` is unpinned. Consider setting a lower bound.
Resolved 4 packages in [TIME]
"###
);
Expand Down Expand Up @@ -8536,6 +8541,7 @@ fn compile_index_url_unsafe_lowest() -> Result<()> {
# via -r requirements.in

----- stderr -----
warning: The direct dependency `anyio` is unpinned. Consider setting a lower bound.
Resolved 1 package in [TIME]
"###
);
Expand Down
1 change: 1 addition & 0 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2382,6 +2382,7 @@ fn install_sdist_resolution_lowest() -> Result<()> {
----- stdout -----

----- stderr -----
warning: The direct dependency `anyio` is unpinned. Consider setting a lower bound.
Resolved 3 packages in [TIME]
Downloaded 3 packages in [TIME]
Installed 3 packages in [TIME]
Expand Down
Loading