Skip to content

Commit

Permalink
Avoid displaying "failed to download" on build failures for local sou…
Browse files Browse the repository at this point in the history
…rce distributions (#6075)

Especially with workspace members (e.g., [this new test
case](https://github.com/astral-sh/uv/pull/6073/files#diff-273076013b4f5a8139defd5dcd24f5d1eb91c0266dceb4448fdeddceb79f7738R1377-R1379)),
I find it very confusing that we say we failed to download these
distributions.
  • Loading branch information
zanieb authored Aug 14, 2024
1 parent dc67023 commit 359f39c
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions crates/uv-distribution/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub enum Error {
CacheEncode(#[from] rmp_serde::encode::Error),

// Build error
#[error("Failed to build: `{0}`")]
Build(String, #[source] anyhow::Error),
#[error(transparent)]
Build(anyhow::Error),
#[error("Failed to build editable: `{0}`")]
BuildEditable(String, #[source] anyhow::Error),
#[error("Built wheel has an invalid filename")]
Expand Down
11 changes: 4 additions & 7 deletions crates/uv-distribution/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,10 +1464,10 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
},
)
.await
.map_err(|err| Error::Build(source.to_string(), err))?
.map_err(Error::Build)?
.wheel(cache_shard)
.await
.map_err(|err| Error::Build(source.to_string(), err))?;
.map_err(Error::Build)?;

// Read the metadata from the wheel.
let filename = WheelFilename::from_str(&disk_filename)?;
Expand Down Expand Up @@ -1555,13 +1555,10 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
},
)
.await
.map_err(|err| Error::Build(source.to_string(), err))?;
.map_err(Error::Build)?;

// Build the metadata.
let dist_info = builder
.metadata()
.await
.map_err(|err| Error::Build(source.to_string(), err))?;
let dist_info = builder.metadata().await.map_err(Error::Build)?;
let Some(dist_info) = dist_info else {
return Ok(None);
};
Expand Down
8 changes: 7 additions & 1 deletion crates/uv-requirements/src/lookahead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum LookaheadError {
Download(BuiltDist, #[source] uv_distribution::Error),
#[error("Failed to download and build: `{0}`")]
DownloadAndBuild(SourceDist, #[source] uv_distribution::Error),
#[error("Failed to build: `{0}`")]
Build(SourceDist, #[source] uv_distribution::Error),
#[error(transparent)]
UnsupportedUrl(#[from] distribution_types::Error),
}
Expand Down Expand Up @@ -180,7 +182,11 @@ impl<'a, Context: BuildContext> LookaheadResolver<'a, Context> {
.map_err(|err| match &dist {
Dist::Built(built) => LookaheadError::Download(built.clone(), err),
Dist::Source(source) => {
LookaheadError::DownloadAndBuild(source.clone(), err)
if source.is_local() {
LookaheadError::Build(source.clone(), err)
} else {
LookaheadError::DownloadAndBuild(source.clone(), err)
}
}
})?;

Expand Down
12 changes: 10 additions & 2 deletions crates/uv-resolver/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,11 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
}
Dist::Built(built_dist) => ResolveError::Fetch(Box::new(built_dist), err),
Dist::Source(source_dist) => {
ResolveError::FetchAndBuild(Box::new(source_dist), err)
if source_dist.is_local() {
ResolveError::Build(Box::new(source_dist), err)
} else {
ResolveError::FetchAndBuild(Box::new(source_dist), err)
}
}
})?;

Expand Down Expand Up @@ -1891,7 +1895,11 @@ impl<InstalledPackages: InstalledPackagesProvider> ResolverState<InstalledPackag
ResolveError::Fetch(Box::new(built_dist), err)
}
Dist::Source(source_dist) => {
ResolveError::FetchAndBuild(Box::new(source_dist), err)
if source_dist.is_local() {
ResolveError::Build(Box::new(source_dist), err)
} else {
ResolveError::FetchAndBuild(Box::new(source_dist), err)
}
}
})?;

Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7527,7 +7527,7 @@ fn lock_mismatched_sources() -> Result<()> {
----- stderr -----
warning: `uv lock` is experimental and may change without warning
warning: `uv.sources` is experimental and may change without warning
error: Failed to download and build: `project @ file://[TEMP_DIR]/`
error: Failed to build: `project @ file://[TEMP_DIR]/`
Caused by: Failed to parse entry for: `uv-public-pypackage`
Caused by: Can't combine URLs from both `project.dependencies` and `tool.uv.sources`
"###);
Expand Down
1 change: 0 additions & 1 deletion crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11776,7 +11776,6 @@ fn incompatible_build_constraint() -> Result<()> {
----- stderr -----
error: Failed to download and build `requests==1.2.0`
Caused by: Failed to build: `requests==1.2.0`
Caused by: Failed to install requirements from setup.py build (resolve)
Caused by: No solution found when resolving: setuptools>=40.8.0
Caused by: Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that the requirements are unsatisfiable.
Expand Down
7 changes: 1 addition & 6 deletions crates/uv/tests/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ dependencies = ["flask==1.0.x"]
----- stdout -----
----- stderr -----
error: Failed to download and build: `project @ file://[TEMP_DIR]/path_dep`
Caused by: Failed to build: `project @ file://[TEMP_DIR]/path_dep`
error: Failed to build: `project @ file://[TEMP_DIR]/path_dep`
Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit code: 1
--- stdout:
configuration error: `project.dependencies[0]` must be pep508
Expand Down Expand Up @@ -3413,7 +3412,6 @@ fn no_build_isolation() -> Result<()> {
----- stderr -----
error: Failed to download and build: `anyio @ https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz`
Caused by: Failed to build: `anyio @ https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz`
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:
Expand Down Expand Up @@ -3484,7 +3482,6 @@ fn respect_no_build_isolation_env_var() -> Result<()> {
----- stderr -----
error: Failed to download and build: `anyio @ https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz`
Caused by: Failed to build: `anyio @ https://files.pythonhosted.org/packages/db/4d/3970183622f0330d3c23d9b8a5f52e365e50381fd484d08e3285104333d3/anyio-4.3.0.tar.gz`
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:
Expand Down Expand Up @@ -6261,7 +6258,6 @@ fn incompatible_build_constraint() -> Result<()> {
----- stderr -----
error: Failed to download and build `requests==1.2.0`
Caused by: Failed to build: `requests==1.2.0`
Caused by: Failed to install requirements from setup.py build (resolve)
Caused by: No solution found when resolving: setuptools>=40.8.0
Caused by: Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that the requirements are unsatisfiable.
Expand Down Expand Up @@ -6338,7 +6334,6 @@ fn install_build_isolation_package() -> Result<()> {
----- stderr -----
error: Failed to download and build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
Caused by: Failed to build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:
Expand Down
1 change: 0 additions & 1 deletion crates/uv/tests/pip_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,6 @@ fn incompatible_build_constraint() -> Result<()> {
----- stderr -----
error: Failed to download and build `requests==1.2.0`
Caused by: Failed to build: `requests==1.2.0`
Caused by: Failed to install requirements from setup.py build (resolve)
Caused by: No solution found when resolving: setuptools>=40.8.0
Caused by: Because you require setuptools>=40.8.0 and setuptools==1, we can conclude that the requirements are unsatisfiable.
Expand Down
2 changes: 0 additions & 2 deletions crates/uv/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ fn sync_build_isolation() -> Result<()> {
----- stderr -----
warning: `uv sync` is experimental and may change without warning
error: Failed to download and build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
Caused by: Failed to build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:
Expand Down Expand Up @@ -617,7 +616,6 @@ fn sync_build_isolation_package() -> Result<()> {
----- stderr -----
warning: `uv sync` is experimental and may change without warning
error: Failed to download and build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
Caused by: Failed to build: `iniconfig @ https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz`
Caused by: Build backend failed to determine metadata through `prepare_metadata_for_build_wheel` with exit status: 1
--- stdout:
Expand Down

0 comments on commit 359f39c

Please sign in to comment.