mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 13:25:00 +00:00
Allow greater than star (torch (>=1.9.*)
) in lenient requirement (#351)
This appeared in the pypi top 8k testing.
This commit is contained in:
parent
fbe28d3b7c
commit
c883b123ac
1 changed files with 22 additions and 1 deletions
|
@ -211,8 +211,9 @@ impl Metadata21 {
|
|||
}
|
||||
|
||||
static MISSING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d)([<>=~^!])").unwrap());
|
||||
|
||||
static NOT_EQUAL_TILDE: Lazy<Regex> = Lazy::new(|| Regex::new(r"!=~((?:\d\.)*\d)").unwrap());
|
||||
/// e.g. `>=1.9.*`
|
||||
static GREATER_THAN_STAR: Lazy<Regex> = Lazy::new(|| Regex::new(r">=(\d+\.\d+)\.\*").unwrap());
|
||||
|
||||
/// Like [`Requirement`], but attempts to correct some common errors in user-provided requirements.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
|
||||
|
@ -247,6 +248,17 @@ impl FromStr for LenientRequirement {
|
|||
}
|
||||
}
|
||||
|
||||
// Given `torch (>=1.9.*)`, rewrite to `torch (>=1.9)`
|
||||
let patched = GREATER_THAN_STAR.replace(s, r">=${1}");
|
||||
if patched != s {
|
||||
if let Ok(requirement) = Requirement::from_str(&patched) {
|
||||
warn!(
|
||||
"Removing star after greater equal operator (before: `{s}`; after: `{patched}`)",
|
||||
);
|
||||
return Ok(Self(requirement));
|
||||
}
|
||||
}
|
||||
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
|
@ -339,4 +351,13 @@ mod tests {
|
|||
let expected: Requirement = Requirement::from_str("jupyter-core (!=5.*,>=4.12)").unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn greater_than_star() {
|
||||
let actual: Requirement = LenientRequirement::from_str("torch (>=1.9.*)")
|
||||
.unwrap()
|
||||
.into();
|
||||
let expected: Requirement = Requirement::from_str("torch (>=1.9)").unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue