Skip to content

Commit

Permalink
Add dedicated lock errors for wheel-only distributions (#7307)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored Sep 11, 2024
1 parent c50eb12 commit c124cda
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
59 changes: 51 additions & 8 deletions crates/uv-resolver/src/lock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ impl Lock {
&self.packages
}

/// Returns the owned [`Package`] entries in this lock.
pub fn into_packages(self) -> Vec<Package> {
self.packages
}

/// Returns the supported Python version range for the lockfile, if present.
pub fn requires_python(&self) -> &RequiresPython {
&self.requires_python
Expand Down Expand Up @@ -1701,6 +1696,10 @@ impl Package {
id: self.id.clone(),
}
.into()),
(true, false) if self.id.source.is_wheel() => Err(LockErrorKind::NoBinaryWheelOnly {
id: self.id.clone(),
}
.into()),
(true, false) => Err(LockErrorKind::NoBinary {
id: self.id.clone(),
}
Expand All @@ -1709,6 +1708,12 @@ impl Package {
id: self.id.clone(),
}
.into()),
(false, false) if self.id.source.is_wheel() => {
Err(LockErrorKind::IncompatibleWheelOnly {
id: self.id.clone(),
}
.into())
}
(false, false) => Err(LockErrorKind::NeitherSourceDistNorWheel {
id: self.id.clone(),
}
Expand Down Expand Up @@ -2465,6 +2470,29 @@ impl Source {
matches!(self, Self::Registry(..) | Self::Git(_, _))
}

/// Returns `true` if the source is that of a wheel.
fn is_wheel(&self) -> bool {
match &self {
Source::Path(path) => {
matches!(
DistExtension::from_path(path).ok(),
Some(DistExtension::Wheel)
)
}
Source::Direct(url, _) => {
matches!(
DistExtension::from_path(url.as_ref()).ok(),
Some(DistExtension::Wheel)
)
}
Source::Directory(..) => false,
Source::Editable(..) => false,
Source::Virtual(..) => false,
Source::Git(..) => false,
Source::Registry(..) => false,
}
}

fn to_toml(&self, table: &mut Table) {
let mut source_table = InlineTable::new();
match *self {
Expand Down Expand Up @@ -3846,7 +3874,7 @@ enum LockErrorKind {
/// distribution.
#[error("distribution {id} can't be installed because it doesn't have a source distribution or wheel for the current platform")]
NeitherSourceDistNorWheel {
/// The ID of the distribution that has a missing base.
/// The ID of the distribution.
id: PackageId,
},
/// An error that occurs when a distribution is marked as both `--no-binary` and `--no-build`.
Expand All @@ -3855,20 +3883,35 @@ enum LockErrorKind {
/// The ID of the distribution.
id: PackageId,
},
/// An error that occurs when a distribution is marked as both `--no-binary`, but no source
/// An error that occurs when a distribution is marked as `--no-binary`, but no source
/// distribution is available.
#[error("distribution {id} can't be installed because it is marked as `--no-binary` but has no source distribution")]
NoBinary {
/// The ID of the distribution.
id: PackageId,
},
/// An error that occurs when a distribution is marked as both `--no-build`, but no binary
/// An error that occurs when a distribution is marked as `--no-build`, but no binary
/// distribution is available.
#[error("distribution {id} can't be installed because it is marked as `--no-build` but has no binary distribution")]
NoBuild {
/// The ID of the distribution.
id: PackageId,
},
/// An error that occurs when a wheel-only distribution is incompatible with the current
/// platform.
#[error(
"distribution {id} can't be installed because the binary distribution is incompatible with the current platform"
)]
IncompatibleWheelOnly {
/// The ID of the distribution.
id: PackageId,
},
/// An error that occurs when a wheel-only source is marked as `--no-binary`.
#[error("distribution {id} can't be installed because it is marked as `--no-binary` but is itself a binary distribution")]
NoBinaryWheelOnly {
/// The ID of the distribution.
id: PackageId,
},
/// An error that occurs when converting between URLs and paths.
#[error("found dependency `{id}` with no locked distribution")]
VerbatimUrl {
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,7 +2195,7 @@ fn sync_wheel_url_source_error() -> Result<()> {
----- stderr -----
Resolved 3 packages in [TIME]
error: distribution cffi==1.17.1 @ direct+https://files.pythonhosted.org/packages/08/fd/cc2fedbd887223f9f5d170c96e57cbf655df9831a6546c1727ae13fa977a/cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl can't be installed because it doesn't have a source distribution or wheel for the current platform
error: distribution cffi==1.17.1 @ direct+https://files.pythonhosted.org/packages/08/fd/cc2fedbd887223f9f5d170c96e57cbf655df9831a6546c1727ae13fa977a/cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl can't be installed because the binary distribution is incompatible with the current platform
"###);

Ok(())
Expand Down Expand Up @@ -2243,7 +2243,7 @@ fn sync_wheel_path_source_error() -> Result<()> {
----- stderr -----
Resolved 3 packages in [TIME]
error: distribution cffi==1.17.1 @ path+cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl can't be installed because it doesn't have a source distribution or wheel for the current platform
error: distribution cffi==1.17.1 @ path+cffi-1.17.1-cp310-cp310-macosx_11_0_arm64.whl can't be installed because the binary distribution is incompatible with the current platform
"###);

Ok(())
Expand Down

0 comments on commit c124cda

Please sign in to comment.