mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-27 04:29:10 +00:00
Ignore invalid extras from PyPI (#1731)
## Summary We don't control these, so it seems preferable _not_ to fail on them, but rather, to just ignore them entirely. (I considered adding a long allow-list, but then questioned the point of it? We'd end up having to extend it if more invalid extras were published in the future.) Closes https://github.com/astral-sh/uv/issues/1633.
This commit is contained in:
parent
402edf1522
commit
a5372d4e4d
2 changed files with 9 additions and 37 deletions
|
@ -7,7 +7,6 @@ use tracing::warn;
|
||||||
|
|
||||||
use pep440_rs::{VersionSpecifiers, VersionSpecifiersParseError};
|
use pep440_rs::{VersionSpecifiers, VersionSpecifiersParseError};
|
||||||
use pep508_rs::{Pep508Error, Requirement};
|
use pep508_rs::{Pep508Error, Requirement};
|
||||||
use uv_normalize::{ExtraName, InvalidNameError};
|
|
||||||
|
|
||||||
/// Ex) `>=7.2.0<8.0.0`
|
/// Ex) `>=7.2.0<8.0.0`
|
||||||
static MISSING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d)([<>=~^!])").unwrap());
|
static MISSING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d)([<>=~^!])").unwrap());
|
||||||
|
@ -123,36 +122,6 @@ impl<'de> Deserialize<'de> for LenientVersionSpecifiers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct LenientExtraName(ExtraName);
|
|
||||||
|
|
||||||
impl LenientExtraName {
|
|
||||||
/// Parse an [`ExtraName`] from a string, but return `None` if the name is `.none`.
|
|
||||||
///
|
|
||||||
/// Some versions of `flit` erroneously included `.none` as an extra name, which is not
|
|
||||||
/// allowed by PEP 508.
|
|
||||||
///
|
|
||||||
/// See: <https://github.com/pypa/flit/issues/228/>
|
|
||||||
pub fn try_parse(name: String) -> Option<Result<Self, InvalidNameError>> {
|
|
||||||
match ExtraName::new(name) {
|
|
||||||
Ok(name) => Some(Ok(Self(name))),
|
|
||||||
Err(err) => {
|
|
||||||
if err.as_str() == ".none" {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Err(err))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<LenientExtraName> for ExtraName {
|
|
||||||
fn from(name: LenientExtraName) -> Self {
|
|
||||||
name.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
|
@ -6,13 +6,14 @@ use std::str::FromStr;
|
||||||
use mailparse::{MailHeaderMap, MailParseError};
|
use mailparse::{MailHeaderMap, MailParseError};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
use pep440_rs::{Version, VersionParseError, VersionSpecifiers, VersionSpecifiersParseError};
|
use pep440_rs::{Version, VersionParseError, VersionSpecifiers, VersionSpecifiersParseError};
|
||||||
use pep508_rs::{Pep508Error, Requirement};
|
use pep508_rs::{Pep508Error, Requirement};
|
||||||
use uv_normalize::{ExtraName, InvalidNameError, PackageName};
|
use uv_normalize::{ExtraName, InvalidNameError, PackageName};
|
||||||
|
|
||||||
use crate::lenient_requirement::LenientRequirement;
|
use crate::lenient_requirement::LenientRequirement;
|
||||||
use crate::{LenientExtraName, LenientVersionSpecifiers};
|
use crate::LenientVersionSpecifiers;
|
||||||
|
|
||||||
/// Python Package Metadata 2.1 as specified in
|
/// Python Package Metadata 2.1 as specified in
|
||||||
/// <https://packaging.python.org/specifications/core-metadata/>.
|
/// <https://packaging.python.org/specifications/core-metadata/>.
|
||||||
|
@ -119,12 +120,14 @@ impl Metadata21 {
|
||||||
})
|
})
|
||||||
.transpose()?;
|
.transpose()?;
|
||||||
let provides_extras = get_all_values("Provides-Extra")
|
let provides_extras = get_all_values("Provides-Extra")
|
||||||
.filter_map(LenientExtraName::try_parse)
|
.filter_map(|provides_extra| match ExtraName::new(provides_extra) {
|
||||||
.map(|result| match result {
|
Ok(extra_name) => Some(extra_name),
|
||||||
Ok(extra_name) => Ok(ExtraName::from(extra_name)),
|
Err(err) => {
|
||||||
Err(err) => Err(err),
|
warn!("Ignoring invalid extra: {err}");
|
||||||
|
None
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
Ok(Metadata21 {
|
Ok(Metadata21 {
|
||||||
metadata_version,
|
metadata_version,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue