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

Improve tracing when encountering invalid requires-python values #1568

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions crates/distribution-types/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use pypi_types::{DistInfoMetadata, Hashes, Yanked};
/// Error converting [`pypi_types::File`] to [`distribution_type::File`].
#[derive(Debug, Error)]
pub enum FileConversionError {
#[error("Invalid 'requires-python' value")]
VersionSpecifiersParseError(#[from] VersionSpecifiersParseError),
#[error("Failed to parse 'requires-python': {0}")]
RequiresPython(String, #[source] VersionSpecifiersParseError),
#[error("Failed to parse URL: {0}")]
Url(String, #[source] url::ParseError),
}
Expand Down Expand Up @@ -44,7 +44,10 @@ impl File {
dist_info_metadata: file.dist_info_metadata,
filename: file.filename,
hashes: file.hashes,
requires_python: file.requires_python.transpose()?,
requires_python: file
.requires_python
.transpose()
.map_err(|err| FileConversionError::RequiresPython(err.line().clone(), err))?,
size: file.size,
upload_time_utc_ms: file.upload_time.map(|dt| dt.timestamp_millis()),
url: if file.url.contains("://") {
Expand Down
7 changes: 7 additions & 0 deletions crates/pep440-rs/src/version_specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ impl std::fmt::Display for VersionSpecifiersParseError {
}
}

impl VersionSpecifiersParseError {
/// The string that failed to parse
pub fn line(&self) -> &String {
&self.inner.line
}
}

impl std::error::Error for VersionSpecifiersParseError {}

/// A version range such such as `>1.2.3`, `<=4!5.6.7-a8.post9.dev0` or `== 4.1.*`. Parse with
Expand Down