mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-24 05:35:04 +00:00
Fixup for >= '2.7'
(#485)
Fixup to allow parsing https://pypi.org/simple/shellingham/?format=application/vnd.pypi.simple.v1+json
This commit is contained in:
parent
7c7daa8f83
commit
ff1100a1ab
1 changed files with 15 additions and 0 deletions
|
@ -18,6 +18,9 @@ static GREATER_THAN_STAR: Lazy<Regex> = Lazy::new(|| Regex::new(r">=(\d+\.\d+)\.
|
|||
static MISSING_DOT: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.\d)+\*").unwrap());
|
||||
/// Ex) `>=3.6,`
|
||||
static TRAILING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\d\.\d)+,$").unwrap());
|
||||
/// Ex) `>= '2.7'`
|
||||
static INVALID_QUOTES: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"((?:~=|==|!=|<=|>=|<|>|===) )*'(\d(?:\.\d)*)'").unwrap());
|
||||
|
||||
/// Regex to match the invalid specifier, replacement to fix it and message about was wrong and
|
||||
/// fixed
|
||||
|
@ -40,6 +43,8 @@ static FIXUPS: &[(&Lazy<Regex>, &str, &str)] = &[
|
|||
(&MISSING_DOT, r"${1}.*", "Inserting missing dot"),
|
||||
// Given `>=3.6,`, rewrite to `>=3.6`
|
||||
(&TRAILING_COMMA, r"${1}", "Removing trailing comma"),
|
||||
// Given `>= '2.7'`, rewrite to `>= 2.7`
|
||||
(&INVALID_QUOTES, r"${1}${2}", "Removing invalid quotes"),
|
||||
];
|
||||
|
||||
/// Like [`Requirement`], but attempts to correct some common errors in user-provided requirements.
|
||||
|
@ -237,4 +242,14 @@ mod tests {
|
|||
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=3.6").unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
/// <https://pypi.org/simple/shellingham/?format=application/vnd.pypi.simple.v1+json>
|
||||
#[test]
|
||||
fn specifier_invalid_quotes() {
|
||||
let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">= '2.7'")
|
||||
.unwrap()
|
||||
.into();
|
||||
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">= 2.7").unwrap();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue