Skip to content

Commit

Permalink
Add fixup for prefect<1.0.0 (#1825)
Browse files Browse the repository at this point in the history
Closes #1798.
  • Loading branch information
charliermarsh authored Feb 21, 2024
1 parent 71ec568 commit 3a34918
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/pypi-types/src/lenient_requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ static TRAILING_COMMA: Lazy<Regex> = Lazy::new(|| Regex::new(r",\s*$").unwrap())
static STRAY_QUOTES: Lazy<Regex> = Lazy::new(|| Regex::new(r#"['"]([*\d])|([*\d])['"]"#).unwrap());
/// Ex) `>dev`
static GREATER_THAN_DEV: Lazy<Regex> = Lazy::new(|| Regex::new(r">dev").unwrap());
/// Ex) `>=9.0.0a1.0`
static TRAILING_ZERO: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(\d+(\.\d)*(a|b|rc|post|dev)\d+)\.0").unwrap());

/// Regex to match the invalid specifier, replacement to fix it and message about was wrong and
/// fixed
Expand All @@ -49,6 +52,8 @@ static FIXUPS: &[(&Lazy<Regex>, &str, &str)] = &[
(&STRAY_QUOTES, r"$1$2", "removing stray quotes"),
// Given `>dev`, rewrite to `>0.0.0dev`
(&GREATER_THAN_DEV, r">0.0.0dev", "assuming 0.0.0dev"),
// Given `>=9.0.0a1.0`, rewrite to `>=9.0.0a1`
(&TRAILING_ZERO, r"${1}", "removing trailing zero"),
];

fn parse_with_fixups<Err, T: FromStr<Err = Err>>(input: &str, type_name: &str) -> Result<T, Err> {
Expand Down Expand Up @@ -334,4 +339,26 @@ mod tests {
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">0.0.0dev").unwrap();
assert_eq!(actual, expected);
}

/// <https://github.com/astral-sh/uv/issues/1798>
#[test]
fn trailing_alpha_zero() {
let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">=9.0.0a1.0")
.unwrap()
.into();
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=9.0.0a1").unwrap();
assert_eq!(actual, expected);

let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">=9.0a1.0")
.unwrap()
.into();
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=9.0a1").unwrap();
assert_eq!(actual, expected);

let actual: VersionSpecifiers = LenientVersionSpecifiers::from_str(">=9a1.0")
.unwrap()
.into();
let expected: VersionSpecifiers = VersionSpecifiers::from_str(">=9a1").unwrap();
assert_eq!(actual, expected);
}
}

0 comments on commit 3a34918

Please sign in to comment.