Skip to content

Commit 6dfe177

Browse files
authored
Use the build options value to improve hints for no wheel / source distribution errors (#9950)
Extends the hints from #9948 with `BuildOptions` context so we can explain a bit more.
1 parent 5e7f80e commit 6dfe177

File tree

14 files changed

+63
-22
lines changed

14 files changed

+63
-22
lines changed

crates/uv-dispatch/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ impl<'a> BuildContext for BuildDispatch<'a> {
218218
OptionsBuilder::new()
219219
.exclude_newer(self.exclude_newer)
220220
.index_strategy(self.index_strategy)
221+
.build_options(self.build_options.clone())
221222
.flexibility(Flexibility::Fixed)
222223
.build(),
223224
&python_requirement,

crates/uv-resolver/src/candidate_selector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) struct CandidateSelector {
2828
impl CandidateSelector {
2929
/// Return a [`CandidateSelector`] for the given [`Manifest`].
3030
pub(crate) fn for_resolution(
31-
options: Options,
31+
options: &Options,
3232
manifest: &Manifest,
3333
env: &ResolverEnvironment,
3434
) -> Self {

crates/uv-resolver/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl std::fmt::Display for NoSolutionError {
370370
&self.fork_urls,
371371
&self.env,
372372
&self.workspace_members,
373-
self.options,
373+
&self.options,
374374
&mut additional_hints,
375375
);
376376
for hint in additional_hints {

crates/uv-resolver/src/options.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use uv_configuration::IndexStrategy;
1+
use uv_configuration::{BuildOptions, IndexStrategy};
22

33
use crate::fork_strategy::ForkStrategy;
44
use crate::{DependencyMode, ExcludeNewer, PrereleaseMode, ResolutionMode};
55

66
/// Options for resolving a manifest.
7-
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
7+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
88
pub struct Options {
99
pub resolution_mode: ResolutionMode,
1010
pub prerelease_mode: PrereleaseMode,
@@ -13,6 +13,7 @@ pub struct Options {
1313
pub exclude_newer: Option<ExcludeNewer>,
1414
pub index_strategy: IndexStrategy,
1515
pub flexibility: Flexibility,
16+
pub build_options: BuildOptions,
1617
}
1718

1819
/// Builder for [`Options`].
@@ -25,6 +26,7 @@ pub struct OptionsBuilder {
2526
exclude_newer: Option<ExcludeNewer>,
2627
index_strategy: IndexStrategy,
2728
flexibility: Flexibility,
29+
build_options: BuildOptions,
2830
}
2931

3032
impl OptionsBuilder {
@@ -82,6 +84,13 @@ impl OptionsBuilder {
8284
self
8385
}
8486

87+
/// Sets the [`BuildOptions`].
88+
#[must_use]
89+
pub fn build_options(mut self, build_options: BuildOptions) -> Self {
90+
self.build_options = build_options;
91+
self
92+
}
93+
8594
/// Builds the options.
8695
pub fn build(self) -> Options {
8796
Options {
@@ -92,6 +101,7 @@ impl OptionsBuilder {
92101
exclude_newer: self.exclude_newer,
93102
index_strategy: self.index_strategy,
94103
flexibility: self.flexibility,
104+
build_options: self.build_options,
95105
}
96106
}
97107
}

crates/uv-resolver/src/pubgrub/report.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use owo_colors::OwoColorize;
77
use pubgrub::{DerivationTree, Derived, External, Map, Range, ReportFormatter, Term};
88
use rustc_hash::FxHashMap;
99

10-
use uv_configuration::IndexStrategy;
10+
use uv_configuration::{IndexStrategy, NoBinary, NoBuild};
1111
use uv_distribution_types::{
1212
IncompatibleDist, IncompatibleSource, IncompatibleWheel, Index, IndexCapabilities,
1313
IndexLocations, IndexUrl,
@@ -522,7 +522,7 @@ impl PubGrubReportFormatter<'_> {
522522
fork_urls: &ForkUrls,
523523
env: &ResolverEnvironment,
524524
workspace_members: &BTreeSet<PackageName>,
525-
options: Options,
525+
options: &Options,
526526
output_hints: &mut IndexSet<PubGrubHint>,
527527
) {
528528
match derivation_tree {
@@ -566,11 +566,13 @@ impl PubGrubReportFormatter<'_> {
566566
IncompatibleDist::Wheel(IncompatibleWheel::NoBinary) => {
567567
output_hints.insert(PubGrubHint::NoBinary {
568568
package: package.clone(),
569+
option: options.build_options.no_binary().clone(),
569570
});
570571
}
571572
IncompatibleDist::Source(IncompatibleSource::NoBuild) => {
572573
output_hints.insert(PubGrubHint::NoBuild {
573574
package: package.clone(),
575+
option: options.build_options.no_build().clone(),
574576
});
575577
}
576578
_ => {}
@@ -974,9 +976,17 @@ pub(crate) enum PubGrubHint {
974976
next_index: IndexUrl,
975977
},
976978
/// No wheels are available for a package, and using source distributions was disabled.
977-
NoBuild { package: PubGrubPackage },
979+
NoBuild {
980+
package: PubGrubPackage,
981+
// excluded from `PartialEq` and `Hash`
982+
option: NoBuild,
983+
},
978984
/// No source distributions are available for a package, and using pre-built wheels was disabled.
979-
NoBinary { package: PubGrubPackage },
985+
NoBinary {
986+
package: PubGrubPackage,
987+
// excluded from `PartialEq` and `Hash`
988+
option: NoBinary,
989+
},
980990
/// An index returned an Unauthorized (401) response.
981991
UnauthorizedIndex { index: IndexUrl },
982992
/// An index returned a Forbidden (403) response.
@@ -1097,8 +1107,8 @@ impl From<PubGrubHint> for PubGrubHintCore {
10971107
PubGrubHint::UncheckedIndex { package, .. } => Self::UncheckedIndex { package },
10981108
PubGrubHint::UnauthorizedIndex { index } => Self::UnauthorizedIndex { index },
10991109
PubGrubHint::ForbiddenIndex { index } => Self::ForbiddenIndex { index },
1100-
PubGrubHint::NoBuild { package } => Self::NoBuild { package },
1101-
PubGrubHint::NoBinary { package } => Self::NoBinary { package },
1110+
PubGrubHint::NoBuild { package, .. } => Self::NoBuild { package },
1111+
PubGrubHint::NoBinary { package, .. } => Self::NoBinary { package },
11021112
}
11031113
}
11041114
}
@@ -1373,19 +1383,33 @@ impl std::fmt::Display for PubGrubHint {
13731383
"403 Forbidden".red(),
13741384
)
13751385
}
1376-
Self::NoBuild { package } => {
1386+
Self::NoBuild { package, option } => {
1387+
let option = match option {
1388+
NoBuild::All => "for all packages (i.e., with `--no-build`)".to_string(),
1389+
NoBuild::Packages(_) => {
1390+
format!("for `{package}` (i.e., with `--no-build-package {package}`)",)
1391+
}
1392+
NoBuild::None => unreachable!(),
1393+
};
13771394
write!(
13781395
f,
1379-
"{}{} Wheels are required for `{}` because building from source is disabled",
1396+
"{}{} Wheels are required for `{}` because building from source is disabled {option}",
13801397
"hint".bold().cyan(),
13811398
":".bold(),
13821399
package.cyan(),
13831400
)
13841401
}
1385-
Self::NoBinary { package } => {
1402+
Self::NoBinary { package, option } => {
1403+
let option = match option {
1404+
NoBinary::All => "for all packages (i.e., with `--no-binary`)".to_string(),
1405+
NoBinary::Packages(_) => {
1406+
format!("for `{package}` (i.e., with `--no-binary-package {package}`)",)
1407+
}
1408+
NoBinary::None => unreachable!(),
1409+
};
13861410
write!(
13871411
f,
1388-
"{}{} A source distributions is required for `{}` because using pre-built wheels is disabled",
1412+
"{}{} A source distribution is required for `{}` because using pre-built wheels is disabled {option}",
13891413
"hint".bold().cyan(),
13901414
":".bold(),
13911415
package.cyan(),

crates/uv-resolver/src/resolver/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl<Provider: ResolverProvider, InstalledPackages: InstalledPackagesProvider>
216216
index: index.clone(),
217217
git: git.clone(),
218218
capabilities: capabilities.clone(),
219-
selector: CandidateSelector::for_resolution(options, &manifest, &env),
219+
selector: CandidateSelector::for_resolution(&options, &manifest, &env),
220220
dependency_mode: options.dependency_mode,
221221
urls: Urls::from_manifest(&manifest, &env, git, options.dependency_mode),
222222
indexes: Indexes::from_manifest(&manifest, &env, options.dependency_mode),
@@ -675,7 +675,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
675675
&self.python_requirement,
676676
&self.conflicts,
677677
self.selector.resolution_strategy(),
678-
self.options,
678+
self.options.clone(),
679679
)
680680
}
681681

@@ -2136,7 +2136,7 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
21362136
fork_urls,
21372137
env,
21382138
self.workspace_members.clone(),
2139-
self.options,
2139+
self.options.clone(),
21402140
))
21412141
}
21422142

crates/uv/src/commands/pip/compile.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ pub(crate) async fn pip_compile(
366366
.dependency_mode(dependency_mode)
367367
.exclude_newer(exclude_newer)
368368
.index_strategy(index_strategy)
369+
.build_options(build_options.clone())
369370
.build();
370371

371372
// Resolve the requirements.

crates/uv/src/commands/pip/install.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ pub(crate) async fn pip_install(
393393
.dependency_mode(dependency_mode)
394394
.exclude_newer(exclude_newer)
395395
.index_strategy(index_strategy)
396+
.build_options(build_options.clone())
396397
.build();
397398

398399
// Resolve the requirements.

crates/uv/src/commands/pip/sync.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ pub(crate) async fn pip_sync(
339339
.dependency_mode(dependency_mode)
340340
.exclude_newer(exclude_newer)
341341
.index_strategy(index_strategy)
342+
.build_options(build_options.clone())
342343
.build();
343344

344345
let resolution = match operations::resolve(

crates/uv/src/commands/project/lock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ async fn do_lock(
472472
.fork_strategy(fork_strategy)
473473
.exclude_newer(exclude_newer)
474474
.index_strategy(index_strategy)
475+
.build_options(build_options.clone())
475476
.build();
476477
let hasher = HashStrategy::Generate;
477478

0 commit comments

Comments
 (0)