From ec799da87b8f8a89a70f5a03167bfd4f4ab37647 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 16 Nov 2026 02:42:29 +0000 Subject: [PATCH] fix(version): compare D[D]MonYYYY versions by date LAMMPS names releases by date, 29Aug2024 or 22Jul2025_update4. cmp_version tokenized those left to right, so the day of the month decided first: 29Aug2024 sorted after 22Jul2025_update4, and 22Jul2025_update4 sorted before 22Jul2025 because a letter sorts before a number. stack gap then named LAMMPS-29Aug2024-foss-2023b-kokkos.eb as the newest recipe outside generation 2026.1, though EasyBuild 5.4.2 has 22Jul2025_update4. parse_version_parts now reads a leading D[D]MonYYYY date as year, month, and day, and an `update` right after it as its number, so the seven LAMMPS versions in easybuild-easyconfigs sort by release and stable update. LAMMPS is the only package there with such versions. Every other version tokenizes as before. On the EESSI 2026.06 site list from the deck demo, the stack gap output changes only in the LAMMPS row, which now names LAMMPS-22Jul2025_update4-foss-2025a-kokkos.eb. Unit tests in version.rs and gap.rs cover the order, a requirement, and the gap row; both fail without the fix. --- changelog.d/+date-versions.bugfix.md | 1 + src/gap.rs | 30 ++++++++ src/version.rs | 101 ++++++++++++++++++++++++++- 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 changelog.d/+date-versions.bugfix.md diff --git a/changelog.d/+date-versions.bugfix.md b/changelog.d/+date-versions.bugfix.md new file mode 100644 index 00000000..3a2e0ae3 --- /dev/null +++ b/changelog.d/+date-versions.bugfix.md @@ -0,0 +1 @@ +Date versions such as LAMMPS's `29Aug2024` compare by year, month and day, and a following `_updateN` by its number, so `stack gap` names a LAMMPS `22Jul2025_update4` recipe as the newest outside the generation instead of `29Aug2024`. Requirements such as `>=29Aug2024` compare the same way. diff --git a/src/gap.rs b/src/gap.rs index 0d57f5ab..d08856f1 100644 --- a/src/gap.rs +++ b/src/gap.rs @@ -761,6 +761,36 @@ mod tests { }) } + #[test] + fn the_newest_date_version_elsewhere_is_the_latest_release() { + let site = names_from_listing("LAMMPS/22Jul2025_update4-foss-2025b-kokkos\n"); + let candidates = vec![ + cand("LAMMPS", "29Aug2024", ("foss", "2023b"), Some("-kokkos")), + cand("LAMMPS", "28Oct2024", ("foss", "2024a"), Some("-kokkos")), + cand("LAMMPS", "22Jul2025", ("foss", "2024a"), Some("-kokkos")), + cand( + "LAMMPS", + "22Jul2025_update4", + ("foss", "2025b"), + Some("-kokkos"), + ), + ]; + let rows = classify( + &site, + &BTreeSet::new(), + &candidates, + &BTreeMap::new(), + &BTreeSet::new(), + &BTreeMap::new(), + &BTreeMap::new(), + ); + assert_eq!(rows[0].route, "no-recipe"); + assert_eq!( + rows[0].newest_elsewhere.as_deref(), + Some("LAMMPS-22Jul2025_update4-foss-2025b-kokkos.eb") + ); + } + #[test] fn routes_each_site_package() { let site = names_from_listing("BLAST+/2.16.0-gompi-2024a\nLAMMPS\nJulia/1.10.4\nCP2K/2025.2-foss-2025a\nMATLAB/2025b\nzlib/1.3.1\n"); diff --git a/src/version.rs b/src/version.rs index 3540b77b..12d43255 100644 --- a/src/version.rs +++ b/src/version.rs @@ -7,6 +7,12 @@ //! separator that is dropped. Example: 1.0rc1 tokenizes to Num(1), Num(0), //! Alpha(rc), Num(1); 2025a tokenizes to Num(2025), Alpha(a). //! +//! A leading D[D]MonYYYY date, as in a release named by its date, tokenizes +//! as year, month, and day: 29Aug2024 is Num(2024), Num(8), Num(29), and +//! sorts before 22Jul2025. An `update` right after the date is dropped and +//! its number kept, so the stable update 22Jul2025_update4 sorts after +//! 22Jul2025. +//! //! Comparison walks both token sequences position by position, and a //! missing token reads as Num(0). Two Num tokens compare numerically; two //! Alpha tokens compare lexicographically (so 2025a is before 2025b). An @@ -33,6 +39,45 @@ pub enum Part { /// alphabetic parts, dropping separator characters. See the module docs /// for the exact tokenization and comparison rules. pub fn parse_version_parts(v: &str) -> Vec { + let Some((date, rest)) = leading_date(v) else { + return tokenize(v); + }; + let mut parts = date.map(Part::Num).to_vec(); + let mut rest = tokenize(rest); + if let [Part::Alpha(word), Part::Num(_), ..] = rest.as_slice() { + if word == "update" { + rest.remove(0); + } + } + parts.extend(rest); + parts +} + +const MONTHS: [&str; 12] = [ + "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", +]; + +/// `[year, month, day]` of a leading `D[D]MonYYYY` date, and what follows it. +fn leading_date(v: &str) -> Option<([u64; 3], &str)> { + let day_len = v.bytes().take_while(u8::is_ascii_digit).count(); + if !(1..=2).contains(&day_len) { + return None; + } + let (day, rest) = v.split_at(day_len); + let day: u64 = day.parse().ok()?; + let month = rest.get(..3)?; + let month = MONTHS + .iter() + .position(|name| name.eq_ignore_ascii_case(month))?; + let rest = &rest[3..]; + if rest.bytes().take_while(u8::is_ascii_digit).count() != 4 || !(1..=31).contains(&day) { + return None; + } + let (year, rest) = rest.split_at(4); + Some(([year.parse().ok()?, month as u64 + 1, day], rest)) +} + +fn tokenize(v: &str) -> Vec { let mut parts = Vec::new(); let mut chars = v.chars().peekable(); while let Some(&c) = chars.peek() { @@ -568,8 +613,23 @@ mod tests { #[test] fn the_order_is_total_so_a_sort_accepts_it() { let mut versions = vec![ - "1.a", "1", "1.0", "1.0.1", "1.0rc1", "4.0.2", "4.0.2-1", "2025a", "2025.1", "0.9.0.4", - "v3", "3.6b", "3.6", "1.0.0", "20260522", + "1.a", + "1", + "1.0", + "1.0.1", + "1.0rc1", + "4.0.2", + "4.0.2-1", + "2025a", + "2025.1", + "0.9.0.4", + "v3", + "3.6b", + "3.6", + "1.0.0", + "20260522", + "29Aug2024", + "22Jul2025_update4", ]; for a in &versions { for b in &versions { @@ -595,4 +655,41 @@ mod tests { assert_eq!(cmp_version("1.2.3", "1.2"), Ordering::Greater); assert_eq!(cmp_version("1.2.0", "1.2"), Ordering::Equal); } + + #[test] + fn date_versions_order_by_release_date_then_update() { + let mut lammps = [ + "22Jul2025_update4", + "29Aug2024", + "2Aug2023_update2", + "22Jul2025", + "28Oct2024", + "23Jun2022", + "29Aug2024_update2", + ]; + lammps.sort_by(|a, b| cmp_version(a, b)); + assert_eq!( + lammps, + [ + "23Jun2022", + "2Aug2023_update2", + "29Aug2024", + "29Aug2024_update2", + "28Oct2024", + "22Jul2025", + "22Jul2025_update4", + ] + ); + assert_eq!(cmp_version("22jul2025", "22Jul2025"), Ordering::Equal); + assert!(matches_req("22Jul2025_update4", ">=29Aug2024")); + assert!(!matches_req("29Aug2024", ">=22Jul2025")); + assert_eq!( + parse_version_parts("2Aug2023_update2"), + [Part::Num(2023), Part::Num(8), Part::Num(2), Part::Num(2)] + ); + assert_eq!( + parse_version_parts("2July2025"), + [Part::Num(2), Part::Alpha("july".into()), Part::Num(2025)] + ); + } }