From 23c7ffb0a8209d049ac5bba000d2577bb524ee8d Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 05:10:46 +0000 Subject: [PATCH 1/9] fix(hierarchy): include sibling composites and topological order EasyBuild toolchain composites such as intel and lfoss list their individual components rather than intermediate subtoolchains like iimkl and lfbf. Walking only downward from parent dependencies omits those sibling composites and appends discoveries ahead of GCCcore. Discover same-version toolchain definitions whose pins are covered by the parent recipe, emit walked members in post-order so subtoolchains precede parents, and keep gompi out of gfbf hierarchies. --- .github/workflows/ci_test.yml | 1 + .../+toolchain-hierarchy-parity.bugfix.md | 1 + src/hierarchy.rs | 145 +++++++---- tests/toolchain_hierarchy_parity.rs | 236 ++++++++++++++++++ 4 files changed, 340 insertions(+), 43 deletions(-) create mode 100644 changelog.d/+toolchain-hierarchy-parity.bugfix.md create mode 100644 tests/toolchain_hierarchy_parity.rs diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 3a1909e4..4a130324 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -218,6 +218,7 @@ jobs: --test stack_shard_robot_versionprefix_field \ --test planner_traversal \ --test hierarchy_universe \ + --test toolchain_hierarchy_parity \ --test jenkins_build_list \ --test lint_fixtures \ --test llms_txt \ diff --git a/changelog.d/+toolchain-hierarchy-parity.bugfix.md b/changelog.d/+toolchain-hierarchy-parity.bugfix.md new file mode 100644 index 00000000..8b5c82d6 --- /dev/null +++ b/changelog.d/+toolchain-hierarchy-parity.bugfix.md @@ -0,0 +1 @@ +Derive `intel` (`iimkl`) and `lfoss` (`lfbf`) intermediate composite toolchains in topological subtoolchain-first order, and exclude `gompi` from `gfbf` hierarchies. diff --git a/src/hierarchy.rs b/src/hierarchy.rs index 821f164c..63b1a50c 100644 --- a/src/hierarchy.rs +++ b/src/hierarchy.rs @@ -596,15 +596,39 @@ pub fn known_hierarchy(parent: &Toolchain) -> Option { /// composites are included only when their definition recipe is in the tree. /// GCCcore is assumed version-paired with GCC (true for all modern /// generations, 2020a+). Non-GCC-family parents return `None`. +fn append_postorder( + node: &Toolchain, + children: &HashMap<(String, String), Vec>, + visiting: &mut std::collections::HashSet<(String, String)>, + visited: &mut std::collections::HashSet<(String, String)>, + members: &mut Vec, +) { + let key = (node.name.clone(), node.version.clone()); + if visited.contains(&key) || !visiting.insert(key.clone()) { + return; + } + if let Some(subs) = children.get(&key) { + for sub in subs { + append_postorder(sub, children, visiting, visited, members); + } + } + visiting.remove(&key); + visited.insert(key); + if !members.iter().any(|m| toolchains_match(m, node)) { + members.push(node.clone()); + } +} + /// A hierarchy read off the tree, for a toolchain no family rule covers. /// /// A toolchain is defined by a recipe, and that recipe's dependencies say what /// it is made of: `iimpi` names `intel-compilers` and `impi`, and /// `intel-compilers` names the `GCCcore` it was built on. Any dependency that -/// other recipes in the tree use *as* a toolchain is a subtoolchain, so the -/// chain can be walked without knowing the family: an unfamiliar composite -/// stops being unplannable, which for a site is the difference between a -/// generation it can bump and one it cannot. +/// other recipes in the tree use *as* a toolchain is a subtoolchain, and any +/// same-version toolchain definition whose pins are a strict subset of the +/// parent's (such as `iimkl` inside `intel` or `lfbf` inside `lfoss`) is an +/// intermediate composite, so the chain can be walked without hardcoding the +/// family and emitted in topological subtoolchain-first order. fn derive_hierarchy_by_walking( parent: &Toolchain, cands: &[Candidate], @@ -613,16 +637,12 @@ fn derive_hierarchy_by_walking( .iter() .map(|candidate| candidate.toolchain.name.as_str()) .collect(); - let mut members: Vec = vec![Toolchain { - name: "system".into(), - version: String::new(), - }]; + let mut children: HashMap<(String, String), Vec> = HashMap::new(); let mut pending = vec![parent.clone()]; - let mut seen: std::collections::HashSet = std::collections::HashSet::new(); - // Breadth-first from the parent down; each level found is inserted before - // the toolchain that named it, so the result stays lowest-first. + let mut seen: std::collections::HashSet<(String, String)> = std::collections::HashSet::new(); while let Some(current) = pending.pop() { - if !seen.insert(format!("{}-{}", current.name, current.version)) { + let current_key = (current.name.clone(), current.version.clone()); + if !seen.insert(current_key.clone()) { continue; } let Some(definition) = cands @@ -631,6 +651,17 @@ fn derive_hierarchy_by_walking( else { continue; }; + let mut subs: Vec = Vec::new(); + let mut push_sub = |tc: Toolchain| { + if !is_system_toolchain(&tc) + && !toolchains_match(&tc, ¤t) + && !subs.iter().any(|m| toolchains_match(m, &tc)) + { + subs.push(tc); + } + }; + let mut def_pins: std::collections::HashSet<(&str, &str)> = + std::collections::HashSet::new(); for dependency in definition .dependencies .iter() @@ -640,34 +671,60 @@ fn derive_hierarchy_by_walking( // `intel` names `imkl-FFTW` at `('iimpi', version)` and never // names iimpi itself, so reading dependency names alone leaves the // MPI level out of the generation's own hierarchy. - let named = dependency.toolchain.as_ref().filter(|toolchain| { - !is_system_toolchain(toolchain) - && !members.iter().any(|m| toolchains_match(m, toolchain)) - }); - if let Some(toolchain) = named { - members.push((*toolchain).clone()); - pending.push((*toolchain).clone()); + if let Some(toolchain) = dependency.toolchain.as_ref() { + push_sub((*toolchain).clone()); } - if !used_as_toolchain.contains(dependency.name.as_str()) { + if let Some(version) = exact_pin_version(&dependency.version_req) { + def_pins.insert((dependency.name.as_str(), version)); + if used_as_toolchain.contains(dependency.name.as_str()) { + push_sub(Toolchain { + name: dependency.name.clone(), + version: version.to_string(), + }); + } + } + } + for sib in cands { + if sib.name == current.name + || sib.version != current.version + || !is_system_toolchain(&sib.toolchain) + || sib.dependencies.is_empty() + || sib.dependencies.len() >= definition.dependencies.len() + { continue; } - let Some(version) = exact_pin_version(&dependency.version_req) else { + if !used_as_toolchain.contains(sib.name.as_str()) + && sib.easyblock.as_deref() != Some("Toolchain") + { continue; - }; - let found = Toolchain { - name: dependency.name.clone(), - version: version.to_string(), - }; - if !members.iter().any(|m| toolchains_match(m, &found)) { - members.push(found.clone()); } - pending.push(found); + let covered = sib.dependencies.iter().all(|dep| { + exact_pin_version(&dep.version_req) + .is_some_and(|v| def_pins.contains(&(dep.name.as_str(), v))) + }); + if covered { + push_sub(Toolchain { + name: sib.name.clone(), + version: sib.version.clone(), + }); + } + } + subs.sort_by(|a, b| a.name.cmp(&b.name).then_with(|| a.version.cmp(&b.version))); + for sub in &subs { + pending.push(sub.clone()); } + children.insert(current_key, subs); } - if members.len() < 2 { + let mut members: Vec = vec![Toolchain { + name: "system".into(), + version: String::new(), + }]; + let mut visiting = std::collections::HashSet::new(); + let mut visited = std::collections::HashSet::new(); + append_postorder(parent, &children, &mut visiting, &mut visited, &mut members); + if members.len() < 3 { return None; } - members.push(parent.clone()); Some(ToolchainHierarchy { parent: parent.clone(), members, @@ -742,18 +799,20 @@ pub fn derive_hierarchy_from_candidates( version: gcc_ver, }, ]; - for comp in COMPOSITES { - if comp == parent.name { - break; // parent itself is appended last (highest rank) - } - let defined = cands - .iter() - .any(|c| c.name == comp && c.version == parent.version); - if defined { - members.push(Toolchain { - name: comp.into(), - version: parent.version.clone(), - }); + if parent.name == "foss" { + for comp in COMPOSITES { + if comp == parent.name { + break; // parent itself is appended last (highest rank) + } + let defined = cands + .iter() + .any(|c| c.name == comp && c.version == parent.version); + if defined { + members.push(Toolchain { + name: comp.into(), + version: parent.version.clone(), + }); + } } } members.push(parent.clone()); diff --git a/tests/toolchain_hierarchy_parity.rs b/tests/toolchain_hierarchy_parity.rs new file mode 100644 index 00000000..7ae31244 --- /dev/null +++ b/tests/toolchain_hierarchy_parity.rs @@ -0,0 +1,236 @@ +use eb_stack::{hierarchy_for_with_tree, parse_easyconfig_tree, solve_from_easyconfigs, Toolchain}; +use std::fs; +use std::path::Path; + +fn write_eb(root: &Path, rel: &str, body: &str) { + let path = root.join(rel); + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path, body).unwrap(); +} + +fn intel_and_lfoss_tree(root: &Path) { + write_eb( + root, + "g/GCCcore/GCCcore-14.3.0.eb", + "name = 'GCCcore'\nversion = '14.3.0'\ntoolchain = SYSTEM\n", + ); + write_eb( + root, + "z/zlib/zlib-1.3.1-GCCcore-14.3.0.eb", + "name = 'zlib'\nversion = '1.3.1'\ntoolchain = {'name': 'GCCcore', 'version': '14.3.0'}\n", + ); + write_eb( + root, + "i/intel-compilers/intel-compilers-2025.2.0.eb", + "easyblock = 'Toolchain'\nname = 'intel-compilers'\nversion = '2025.2.0'\ntoolchain = SYSTEM\ndependencies = [('GCCcore', '14.3.0')]\n", + ); + write_eb( + root, + "i/impi/impi-2021.16.1-intel-compilers-2025.2.0.eb", + "name = 'impi'\nversion = '2021.16.1'\ntoolchain = {'name': 'intel-compilers', 'version': '2025.2.0'}\n", + ); + write_eb( + root, + "i/imkl/imkl-2025.2.0.eb", + "name = 'imkl'\nversion = '2025.2.0'\ntoolchain = SYSTEM\n", + ); + write_eb( + root, + "i/iimpi/iimpi-2025b.eb", + "easyblock = 'Toolchain'\nname = 'iimpi'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [('GCCcore', '14.3.0'), ('intel-compilers', '2025.2.0'), ('impi', '2021.16.1', '', ('intel-compilers', '2025.2.0'))]\n", + ); + write_eb( + root, + "i/iimkl/iimkl-2025b.eb", + "easyblock = 'Toolchain'\nname = 'iimkl'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [('intel-compilers', '2025.2.0'), ('imkl', '2025.2.0', '', SYSTEM)]\n", + ); + write_eb( + root, + "i/imkl-FFTW/imkl-FFTW-2025.2.0-iimpi-2025b.eb", + "name = 'imkl-FFTW'\nversion = '2025.2.0'\ntoolchain = {'name': 'iimpi', 'version': '2025b'}\n", + ); + write_eb( + root, + "i/intel/intel-2025b.eb", + "easyblock = 'Toolchain'\nname = 'intel'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [\n ('GCCcore', '14.3.0'),\n ('intel-compilers', '2025.2.0'),\n ('impi', '2021.16.1', '', ('intel-compilers', '2025.2.0')),\n ('imkl', '2025.2.0', '', SYSTEM),\n ('imkl-FFTW', '2025.2.0', '', ('iimpi', '2025b')),\n]\n", + ); + write_eb( + root, + "s/SciPy-bundle/SciPy-bundle-2025.07-iimkl-2025b.eb", + "name = 'SciPy-bundle'\nversion = '2025.07'\ntoolchain = {'name': 'iimkl', 'version': '2025b'}\n", + ); + write_eb( + root, + "a/ASAP3/ASAP3-3.13.11-intel-2025b.eb", + "name = 'ASAP3'\nversion = '3.13.11'\ntoolchain = {'name': 'intel', 'version': '2025b'}\ndependencies = [('SciPy-bundle', '2025.07')]\n", + ); + + write_eb( + root, + "l/llvm-compilers/llvm-compilers-20.1.8.eb", + "easyblock = 'Toolchain'\nname = 'llvm-compilers'\nversion = '20.1.8'\ntoolchain = SYSTEM\ndependencies = [('GCCcore', '14.3.0')]\n", + ); + write_eb( + root, + "o/OpenMPI/OpenMPI-5.0.8-llvm-compilers-20.1.8.eb", + "name = 'OpenMPI'\nversion = '5.0.8'\ntoolchain = {'name': 'llvm-compilers', 'version': '20.1.8'}\n", + ); + write_eb( + root, + "f/FlexiBLAS/FlexiBLAS-3.4.5-llvm-compilers-20.1.8.eb", + "name = 'FlexiBLAS'\nversion = '3.4.5'\ntoolchain = {'name': 'llvm-compilers', 'version': '20.1.8'}\n", + ); + write_eb( + root, + "f/FFTW/FFTW-3.3.10-llvm-compilers-20.1.8.eb", + "name = 'FFTW'\nversion = '3.3.10'\ntoolchain = {'name': 'llvm-compilers', 'version': '20.1.8'}\n", + ); + write_eb( + root, + "l/lompi/lompi-2025b.eb", + "easyblock = 'Toolchain'\nname = 'lompi'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [('llvm-compilers', '20.1.8'), ('OpenMPI', '5.0.8', '', ('llvm-compilers', '20.1.8'))]\n", + ); + write_eb( + root, + "l/lfbf/lfbf-2025b.eb", + "easyblock = 'Toolchain'\nname = 'lfbf'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [('llvm-compilers', '20.1.8'), ('FlexiBLAS', '3.4.5', '', ('llvm-compilers', '20.1.8')), ('FFTW', '3.3.10', '', ('llvm-compilers', '20.1.8'))]\n", + ); + write_eb( + root, + "l/lfoss/lfoss-2025b.eb", + "easyblock = 'Toolchain'\nname = 'lfoss'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [\n ('llvm-compilers', '20.1.8'),\n ('OpenMPI', '5.0.8', '', ('llvm-compilers', '20.1.8')),\n ('FlexiBLAS', '3.4.5', '', ('llvm-compilers', '20.1.8')),\n ('FFTW', '3.3.10', '', ('llvm-compilers', '20.1.8')),\n ('ScaLAPACK', '2.2.2', '', ('lompi', '2025b')),\n]\n", + ); + write_eb( + root, + "s/ScaLAPACK/ScaLAPACK-2.2.2-lompi-2025b.eb", + "name = 'ScaLAPACK'\nversion = '2.2.2'\ntoolchain = {'name': 'lompi', 'version': '2025b'}\n", + ); + write_eb( + root, + "n/networkx/networkx-3.5-lfbf-2025b.eb", + "name = 'networkx'\nversion = '3.5'\ntoolchain = {'name': 'lfbf', 'version': '2025b'}\n", + ); +} + +#[test] +fn intel_hierarchy_includes_iimkl_and_solves_iimkl_deps() { + let tmp = tempfile::tempdir().unwrap(); + let ec_root = tmp.path().join("easyconfigs"); + intel_and_lfoss_tree(&ec_root); + let cands = parse_easyconfig_tree(&ec_root).unwrap().candidates; + + let intel_h = hierarchy_for_with_tree( + &Toolchain { + name: "intel".into(), + version: "2025b".into(), + }, + None, + &cands, + ) + .unwrap(); + assert_eq!( + intel_h.member_labels(), + vec![ + "system", + "GCCcore-14.3.0", + "intel-compilers-2025.2.0", + "iimkl-2025b", + "iimpi-2025b", + "intel-2025b", + ] + ); + + let iimpi_h = hierarchy_for_with_tree( + &Toolchain { + name: "iimpi".into(), + version: "2025b".into(), + }, + None, + &cands, + ) + .unwrap(); + assert_eq!( + iimpi_h.member_labels(), + vec![ + "system", + "GCCcore-14.3.0", + "intel-compilers-2025.2.0", + "iimpi-2025b", + ] + ); + + let policy_path = tmp.path().join("policy.json"); + let lock_path = tmp.path().join("lock.json"); + fs::write( + &policy_path, + r#"{"toolchain":{"name":"intel","version":"2025b"},"roots":["ASAP3"]}"#, + ) + .unwrap(); + let lock = solve_from_easyconfigs(&[&ec_root], &policy_path, None, &lock_path, None).unwrap(); + assert_eq!(lock.package("SciPy-bundle").unwrap().version, "2025.07"); +} + +#[test] +fn lfoss_hierarchy_includes_lfbf_and_orders_gcccore_first() { + let tmp = tempfile::tempdir().unwrap(); + let ec_root = tmp.path().join("easyconfigs"); + intel_and_lfoss_tree(&ec_root); + let cands = parse_easyconfig_tree(&ec_root).unwrap().candidates; + + let lfoss_h = hierarchy_for_with_tree( + &Toolchain { + name: "lfoss".into(), + version: "2025b".into(), + }, + None, + &cands, + ) + .unwrap(); + assert_eq!( + lfoss_h.member_labels(), + vec![ + "system", + "GCCcore-14.3.0", + "llvm-compilers-20.1.8", + "lfbf-2025b", + "lompi-2025b", + "lfoss-2025b", + ] + ); +} + +#[test] +fn gfbf_hierarchy_excludes_gompi() { + let tmp = tempfile::tempdir().unwrap(); + let ec_root = tmp.path().join("easyconfigs"); + write_eb( + &ec_root, + "g/GCC/GCC-14.3.0.eb", + "name = 'GCC'\nversion = '14.3.0'\ntoolchain = SYSTEM\ndependencies = [('GCCcore', '14.3.0')]\n", + ); + write_eb( + &ec_root, + "g/gompi/gompi-2025b.eb", + "easyblock = 'Toolchain'\nname = 'gompi'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [('GCC', '14.3.0')]\n", + ); + write_eb( + &ec_root, + "g/gfbf/gfbf-2025b.eb", + "easyblock = 'Toolchain'\nname = 'gfbf'\nversion = '2025b'\ntoolchain = SYSTEM\ndependencies = [('GCC', '14.3.0')]\n", + ); + let cands = parse_easyconfig_tree(&ec_root).unwrap().candidates; + + let gfbf_h = hierarchy_for_with_tree( + &Toolchain { + name: "gfbf".into(), + version: "2025b".into(), + }, + None, + &cands, + ) + .unwrap(); + assert_eq!( + gfbf_h.member_labels(), + vec!["system", "GCCcore-14.3.0", "GCC-14.3.0", "gfbf-2025b"] + ); +} From 3e4f3afb124abb46553d631fb11342179b05cabf Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 05:18:10 +0000 Subject: [PATCH 2/9] fix(parse): resolve cudaver templates in toolchain versions EasyBuild recipes for NVHPC toolchains use %(cudaver)s in toolchain.version when declaring a CUDA dependency, or inherit cudaver from a CUDA-suffixed toolchain version without repeating CUDA in their dependency list. Both cases left %(cudaver)s unexpanded. Expand toolchain fields on the dependency template pass, extract cudaver from CUDA-prefixed toolchain or versionsuffix labels when no CUDA dependency is declared, and admit suffixed toolchain definitions when scoping solver candidates. --- .github/workflows/ci_test.yml | 1 + .../+cuda-toolchain-templates.bugfix.md | 1 + src/eb_parse.rs | 84 ++++++++++++++---- src/resolvo_provider.rs | 7 +- tests/cuda_toolchain_templates.rs | 86 +++++++++++++++++++ 5 files changed, 160 insertions(+), 19 deletions(-) create mode 100644 changelog.d/+cuda-toolchain-templates.bugfix.md create mode 100644 tests/cuda_toolchain_templates.rs diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 4a130324..582ffc2c 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -189,6 +189,7 @@ jobs: --test cli_ergonomics \ --test cli_reference \ --test cuda_cc \ + --test cuda_toolchain_templates \ --test component_reach \ --test doc_walkthrough \ --test eb_robot_paths \ diff --git a/changelog.d/+cuda-toolchain-templates.bugfix.md b/changelog.d/+cuda-toolchain-templates.bugfix.md new file mode 100644 index 00000000..ca8a108b --- /dev/null +++ b/changelog.d/+cuda-toolchain-templates.bugfix.md @@ -0,0 +1 @@ +Expand `%(cudaver)s` and other dependency version templates inside `toolchain.version`, derive `cudaver` from `CUDA-` toolchain labels when no `CUDA` dependency is listed, and admit suffixed toolchain definitions in `dependency_candidate_scope`. diff --git a/src/eb_parse.rs b/src/eb_parse.rs index fb5d7fc0..cc30e0e1 100644 --- a/src/eb_parse.rs +++ b/src/eb_parse.rs @@ -2271,8 +2271,45 @@ const DEP_VERSION_TEMPLATES: &[(&str, &str)] = &[ ("Perl", "perl"), ]; -/// The `%(ver)s` family, taken from what a recipe depends on. -fn dependency_version_templates(deps: &[&[ResolvedDep]]) -> HashMap { +fn insert_prefixed_version_templates(tv: &mut HashMap, prefix: &str, ver: &str) { + if ver.is_empty() || !ver.starts_with(|c: char| c.is_ascii_digit()) { + return; + } + let parts: Vec<&str> = ver.split('.').collect(); + tv.insert(format!("{prefix}ver"), ver.to_string()); + tv.insert(format!("{prefix}majver"), parts[0].to_string()); + if parts.len() > 1 { + tv.insert(format!("{prefix}minver"), parts[1].to_string()); + tv.insert( + format!("{prefix}shortver"), + format!("{}.{}", parts[0], parts[1]), + ); + } +} + +fn extract_cuda_version_from_label(label: &str) -> Option<&str> { + for tag in ["CUDA-", "CUDAcore-"] { + if let Some(idx) = label.find(tag) { + let rest = &label[idx + tag.len()..]; + if rest.starts_with(|c: char| c.is_ascii_digit()) { + let end = rest.find('-').unwrap_or(rest.len()); + let ver = &rest[..end]; + if !ver.is_empty() { + return Some(ver); + } + } + } + } + None +} + +/// The `%(ver)s` family, taken from what a recipe depends on, with a +/// fallback to a CUDA version named in the toolchain version or versionsuffix. +fn dependency_version_templates( + deps: &[&[ResolvedDep]], + toolchain: &Toolchain, + versionsuffix: Option<&str>, +) -> HashMap { let mut tv = HashMap::new(); for dep in deps.iter().flat_map(|list| list.iter()) { let Some((_, prefix)) = DEP_VERSION_TEMPLATES @@ -2284,18 +2321,13 @@ fn dependency_version_templates(deps: &[&[ResolvedDep]]) -> HashMap=3.11` names no single // number to substitute, and guessing one would be worse than leaving // the template visible. - if dep.version.is_empty() || !dep.version.starts_with(|c: char| c.is_ascii_digit()) { - continue; - } - let parts: Vec<&str> = dep.version.split('.').collect(); - tv.insert(format!("{prefix}ver"), dep.version.clone()); - tv.insert(format!("{prefix}majver"), parts[0].to_string()); - if parts.len() > 1 { - tv.insert(format!("{prefix}minver"), parts[1].to_string()); - tv.insert( - format!("{prefix}shortver"), - format!("{}.{}", parts[0], parts[1]), - ); + insert_prefixed_version_templates(&mut tv, prefix, &dep.version); + } + if !tv.contains_key("cudaver") { + if let Some(ver) = extract_cuda_version_from_label(&toolchain.version) + .or_else(|| versionsuffix.and_then(extract_cuda_version_from_label)) + { + insert_prefixed_version_templates(&mut tv, "cuda", ver); } } tv @@ -2808,11 +2840,11 @@ fn resolve_easyconfig_str_inner(src: &str, arch: &str) -> Result".into(), e))?; let vs_for_templates = versionsuffix_raw.clone().unwrap_or_default(); - let mut templates = build_templates(&name, &version, &vs_for_templates, &toolchain, arch); + let mut templates = build_templates(&name, &version, &vs_for_templates, &toolchain_raw, arch); // The defaults in build_templates are what EasyBuild uses when the recipe // leaves the parameter unset. An assignment has to win, or GITHUB_SOURCE // points at the lowercased software name instead of the account the recipe @@ -2824,6 +2856,10 @@ fn resolve_easyconfig_str_inner(src: &str, arch: &str) -> Result Result Result| -> Result, ParseError> { @@ -2913,6 +2960,7 @@ fn resolve_easyconfig_str_inner(src: &str, arch: &str) -> Result Date: Fri, 20 Nov 2026 05:25:03 +0000 Subject: [PATCH 3/9] fix(eb_parse): parse Python raw and raw f-string literals Accept Python raw strings (`r'...'` / `r"..."`, including triple-quoted forms) and raw f-strings (`rf"..."` / `fr"..."`) in `eb_parse`, keeping backslashes verbatim while expanding `{expr}` holes inside raw f-strings. Also teach `strip_comments` to track `\` escapes in normal strings so escaped quotes do not prematurely end comment protection. Raw literals were the top cause of silent `exts_list` drops across the `easybuild-easyconfigs` `develop` corpus (188 `unknown name 'r'` errors, including `PyStan-3.10.0-foss-2025a.eb` dropping all 6 extensions); dropped extension lists fall from 199 to 11 across 12,222 recipes. --- .github/workflows/ci_test.yml | 1 + changelog.d/+raw-string-literals.bugfix.md | 1 + src/eb_parse.rs | 95 +++++++++++++++++----- tests/raw_string_literals.rs | 52 ++++++++++++ 4 files changed, 127 insertions(+), 22 deletions(-) create mode 100644 changelog.d/+raw-string-literals.bugfix.md create mode 100644 tests/raw_string_literals.rs diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 582ffc2c..4663fd07 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -234,6 +234,7 @@ jobs: --test pr_overlap_easyconfigs \ --test pr_overlap_easyconfigs_open \ --test pypi_cran_extend \ + --test raw_string_literals \ --test rebuild_set \ --test recipe_commands \ --test repro_scoring \ diff --git a/changelog.d/+raw-string-literals.bugfix.md b/changelog.d/+raw-string-literals.bugfix.md new file mode 100644 index 00000000..045f7216 --- /dev/null +++ b/changelog.d/+raw-string-literals.bugfix.md @@ -0,0 +1 @@ +Parse Python raw string literals (`r"..."`, `r'...'`, `r"""..."""`) and raw f-strings (`rf"..."`, `fr"..."`) in `eb_parse` instead of rejecting the prefix as an unknown identifier and dropping `exts_list` or command parameters. diff --git a/src/eb_parse.rs b/src/eb_parse.rs index cc30e0e1..c12b7cc3 100644 --- a/src/eb_parse.rs +++ b/src/eb_parse.rs @@ -296,6 +296,10 @@ fn strip_comments(src: &str) -> String { i += 3; continue; } + if c == b'\\' && (in_s || in_d) { + i += 2; + continue; + } if c == b'\'' && !in_d { in_s = !in_s; } else if c == b'"' && !in_s { @@ -1029,7 +1033,7 @@ impl<'a> Parser<'a> { // joining across a newline there would swallow the next statement. let join_strings = matches!(left, Value::Str(_)) && (self.depth > 0 || !crossed_line) - && (matches!(self.peek(), Some(b'\'' | b'"')) || self.starts_fstring()); + && (matches!(self.peek(), Some(b'\'' | b'"')) || self.starts_prefixed_string()); if join_strings { let right = self.parse_postfix()?; left = match (left, right) { @@ -1116,7 +1120,9 @@ impl<'a> Parser<'a> { return Err(self.err("expected expression, got EOF")); }; match c { - b'f' | b'F' if self.starts_fstring() => self.parse_fstring(), + b'f' | b'F' | b'r' | b'R' if self.starts_prefixed_string() => { + self.parse_prefixed_string() + } b'\'' | b'"' => self.parse_string(), b'[' => self.parse_list(), b'(' => self.parse_tuple_or_group(), @@ -1128,6 +1134,10 @@ impl<'a> Parser<'a> { } fn parse_string(&mut self) -> Result { + self.parse_string_with_raw(false) + } + + fn parse_string_with_raw(&mut self, raw: bool) -> Result { self.skip_ws(); let quote = self.bump().ok_or_else(|| self.err("expected string"))?; // Triple-quoted @@ -1147,12 +1157,32 @@ impl<'a> Parser<'a> { .map_err(|e| self.err(e.to_string()))? .to_string(); self.pos += 3; - return Ok(Value::Str(unescape_python_str(&s))); + return Ok(Value::Str(if raw { s } else { unescape_python_str(&s) })); + } + if raw && self.src[self.pos] == b'\\' && self.pos + 1 < self.src.len() { + self.pos += 2; + } else { + self.pos += 1; } - self.pos += 1; } return Err(self.err("unterminated triple-quoted string")); } + if raw { + let start = self.pos; + while let Some(c) = self.bump() { + if c == quote { + let s = std::str::from_utf8(&self.src[start..self.pos - 1]) + .map_err(|e| self.err(e.to_string()))? + .to_string(); + return Ok(Value::Str(s)); + } + if c == b'\\' { + self.bump() + .ok_or_else(|| self.err("unterminated string escape"))?; + } + } + return Err(self.err("unterminated string")); + } let mut out = String::new(); while let Some(c) = self.bump() { if c == quote { @@ -1197,30 +1227,51 @@ impl<'a> Parser<'a> { sub.parse_expr() } - /// Whether what follows is an f-string rather than a name beginning with f. - fn starts_fstring(&self) -> bool { - let mut at = self.pos; - // Accept fr'' and rf'' as well, which a recipe writes for a path. - while matches!(self.src.get(at), Some(b'f' | b'F' | b'r' | b'R')) && at < self.pos + 2 { - at += 1; + /// Whether what follows is a prefixed (`r`, `f`, `fr`, `rf`) string literal + /// rather than an identifier beginning with `r` or `f`. + fn starts_prefixed_string(&self) -> bool { + let Some(first) = self.src.get(self.pos) else { + return false; + }; + let is_f = |b: u8| matches!(b, b'f' | b'F'); + let is_r = |b: u8| matches!(b, b'r' | b'R'); + if !(is_f(*first) || is_r(*first)) { + return false; + } + if matches!(self.src.get(self.pos + 1), Some(b'\'' | b'"')) { + return true; } - at > self.pos && matches!(self.src.get(at), Some(b'\'' | b'"')) + let Some(second) = self.src.get(self.pos + 1) else { + return false; + }; + let valid_pair = (is_f(*first) && is_r(*second)) || (is_r(*first) && is_f(*second)); + valid_pair && matches!(self.src.get(self.pos + 2), Some(b'\'' | b'"')) } - /// An f-string, with `{name}` filled from what the file has defined. + /// Parse `r'...'`, `f'...'`, `fr'...'`, or `rf'...'` string literals. /// - /// 221 recipes use one and 47 put it in a field that decides identity or - /// dependencies, so a parser that stops at the `f` reads those as having - /// no version at all. Only a bare name is substituted: a format spec or a - /// conversion is an error rather than a guess, because a silently - /// mis-rendered version is worse than a recipe that is skipped. - fn parse_fstring(&mut self) -> Result { - while matches!(self.peek(), Some(b'f' | b'F' | b'r' | b'R')) { - self.pos += 1; + /// Only a bare name or expression inside `{...}` is substituted in f-strings; + /// raw prefixes preserve backslashes verbatim. + fn parse_prefixed_string(&mut self) -> Result { + let mut is_f = false; + let mut is_r = false; + while let Some(b) = self.peek() { + if matches!(b, b'f' | b'F') { + is_f = true; + self.pos += 1; + } else if matches!(b, b'r' | b'R') { + is_r = true; + self.pos += 1; + } else { + break; + } } - let Value::Str(raw) = self.parse_string()? else { - return Err(self.err("f-string body is not a string")); + let Value::Str(raw) = self.parse_string_with_raw(is_r)? else { + return Err(self.err("prefixed string body is not a string")); }; + if !is_f { + return Ok(Value::Str(raw)); + } let mut out = String::new(); let mut rest = raw.as_str(); while let Some(at) = rest.find(['{', '}']) { diff --git a/tests/raw_string_literals.rs b/tests/raw_string_literals.rs new file mode 100644 index 00000000..ac5b2371 --- /dev/null +++ b/tests/raw_string_literals.rs @@ -0,0 +1,52 @@ +use eb_stack::resolve_easyconfig_str_reporting; + +#[test] +fn exts_list_with_raw_string_keeps_all_extensions() { + let src = r#" +easyblock = 'PythonBundle' +name = 'PyStan' +version = '3.10.0' +toolchain = {'name': 'foss', 'version': '2025a'} +dependencies = [('Python', '3.13.1')] +exts_list = [ + ('clikit', '0.6.2', { + 'preinstallopts': r"sed -i 's/\^0.3.0/>=0.3.0/' pyproject.toml && ", + }), + ('marshmallow', '3.26.1'), + ('webargs', '8.7.0'), + ('httpstan', '4.13.0'), + ('pysimdjson', '7.0.2'), + (name, version, { + 'modulename': 'stan', + }), +] +"#; + let (ec, skipped) = resolve_easyconfig_str_reporting(src).unwrap(); + assert!( + skipped.is_empty(), + "expected no skipped statements, got {skipped:?}" + ); + assert_eq!(ec.exts_list.len(), 6); + assert_eq!(ec.exts_list[0].name, "clikit"); + assert_eq!(ec.exts_list[5].name, "PyStan"); + assert_eq!(ec.exts_list[5].version, "3.10.0"); +} + +#[test] +fn raw_and_rf_strings_preserve_backslashes_and_interpolate() { + let src = r#" +name = 'dorado' +version = '2.1.2' +toolchain = {'name': 'foss', 'version': '2025a'} +local_tag = 'OpenSSL' +preconfigopts = r"sed -i 's/a\nb/c/' CMakeLists.txt && " +configopts = rf"-DFLAG={local_tag}\path" +description = r"""multi\nline""" +"#; + let (ec, skipped) = resolve_easyconfig_str_reporting(src).unwrap(); + assert!( + skipped.is_empty(), + "expected no skipped statements, got {skipped:?}" + ); + assert_eq!(ec.configopts.as_deref(), Some(r"-DFLAG=OpenSSL\path")); +} From 4a48c8d6add27a2dd1c946ff28d527a36448698a Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 05:32:23 +0000 Subject: [PATCH 4/9] fix(eb_parse): match combined versionsuffix pins and append commas Accept exact `version + versionsuffix` matches in `candidate_matches_dep_core` when `dep.versionsuffix` is unset so `check_recipe_deps` resolves pins such as `('MCR', 'R2019b.8')` against `MCR` (`version = 'R2019b'`, `versionsuffix = '.8'`), matching EasyBuild and `build_order::satisfies` while continuing to reject suffixed builds for plain version pins. Also allow an optional trailing comma inside `list.append(...,)` statements in `try_list_append`, eliminating all four dropped dependency appends (`Extrae` and `Stata`) across `easybuild-easyconfigs` `develop`. --- .github/workflows/ci_test.yml | 1 + .../+dep-matching-and-append.bugfix.md | 1 + src/eb_parse.rs | 26 +++--- tests/dep_matching_and_append.rs | 85 +++++++++++++++++++ 4 files changed, 103 insertions(+), 10 deletions(-) create mode 100644 changelog.d/+dep-matching-and-append.bugfix.md create mode 100644 tests/dep_matching_and_append.rs diff --git a/.github/workflows/ci_test.yml b/.github/workflows/ci_test.yml index 4663fd07..57d97d83 100644 --- a/.github/workflows/ci_test.yml +++ b/.github/workflows/ci_test.yml @@ -235,6 +235,7 @@ jobs: --test pr_overlap_easyconfigs_open \ --test pypi_cran_extend \ --test raw_string_literals \ + --test dep_matching_and_append \ --test rebuild_set \ --test recipe_commands \ --test repro_scoring \ diff --git a/changelog.d/+dep-matching-and-append.bugfix.md b/changelog.d/+dep-matching-and-append.bugfix.md new file mode 100644 index 00000000..abf10edd --- /dev/null +++ b/changelog.d/+dep-matching-and-append.bugfix.md @@ -0,0 +1 @@ +Match combined `version + versionsuffix` dependency pins in `candidate_matches_dep_for_recipe` when `dep.versionsuffix` is unset (such as `MCR/R2019b.8`), and accept trailing commas in `list.append(...)` statements. diff --git a/src/eb_parse.rs b/src/eb_parse.rs index c12b7cc3..b1141350 100644 --- a/src/eb_parse.rs +++ b/src/eb_parse.rs @@ -586,6 +586,10 @@ impl<'a> Parser<'a> { } let arg = self.parse_expr()?; self.skip_ws(); + if self.peek() == Some(b',') { + self.pos += 1; + self.skip_ws(); + } if self.bump() != Some(b')') { return Err(self.err(format!("expected ')' after {name}.append"))); } @@ -4220,17 +4224,19 @@ fn candidate_matches_dep_core( if c.name != dep.name { return false; } - // Match the EasyBuild install stem (versionprefix + bare version), so a - // dep of mpp-1.0 selects the prefixed Mol and a dep of 1.0 selects plain. - if !matches_req( - &c.install_version_stem(), - &version_field_to_req(&dep.version), - ) { - return false; - } - let want_vs = dep.versionsuffix.as_deref().unwrap_or(""); + // Match the EasyBuild install stem (versionprefix + bare version), or + // stem + versionsuffix when the dependency carries an exact combined + // version string such as MCR R2019b.8 with no separate suffix tuple. + let req = version_field_to_req(&dep.version); + let stem = c.install_version_stem(); let got_vs = c.versionsuffix.as_deref().unwrap_or(""); - if want_vs != got_vs { + let want_vs = dep.versionsuffix.as_deref().unwrap_or(""); + let stem_match = matches_req(&stem, &req) && want_vs == got_vs; + let combined_match = dep.versionsuffix.is_none() + && !got_vs.is_empty() + && crate::version::requirement_is_exact(&req) + && matches_req(&format!("{stem}{got_vs}"), &req); + if !stem_match && !combined_match { return false; } if let Some(tc) = &dep.toolchain { diff --git a/tests/dep_matching_and_append.rs b/tests/dep_matching_and_append.rs new file mode 100644 index 00000000..eacbc7c9 --- /dev/null +++ b/tests/dep_matching_and_append.rs @@ -0,0 +1,85 @@ +use eb_stack::{ + candidate_matches_dep, check_recipe_deps, resolve_easyconfig_str, + resolve_easyconfig_str_for_arch, +}; + +#[test] +fn check_recipe_deps_matches_version_plus_versionsuffix_pin() { + let mcr = resolve_easyconfig_str( + "name = 'MCR'\n\ + version = 'R2019b'\n\ + local_update = '8'\n\ + versionsuffix = '.%s' % local_update\n\ + toolchain = SYSTEM\n", + ) + .expect("MCR"); + let freesurfer = resolve_easyconfig_str( + "name = 'FreeSurfer'\n\ + version = '7.3.2'\n\ + versionsuffix = '-centos7_x86_64'\n\ + toolchain = SYSTEM\n\ + dependencies = [('MCR', 'R2019b.8')]\n", + ) + .expect("FreeSurfer"); + + let mcr_cand = mcr.to_candidate(); + assert!( + candidate_matches_dep(&mcr_cand, &freesurfer.dependencies[0]), + "candidate_matches_dep must match MCR R2019b + .8 against R2019b.8" + ); + + let check = check_recipe_deps(&freesurfer, &[mcr_cand]); + assert!( + check.ok(), + "check_recipe_deps must resolve FreeSurfer -> MCR/R2019b.8: {:?}", + check.missing + ); + + let python_bare = resolve_easyconfig_str( + "name = 'Python'\n\ + version = '3.12.3'\n\ + versionsuffix = '-bare'\n\ + toolchain = {'name': 'GCCcore', 'version': '13.3.0'}\n", + ) + .expect("Python-bare"); + let app = resolve_easyconfig_str( + "name = 'App'\n\ + version = '1.0'\n\ + toolchain = {'name': 'GCCcore', 'version': '13.3.0'}\n\ + dependencies = [('Python', '3.12.3')]\n", + ) + .expect("App"); + assert!( + !candidate_matches_dep(&python_bare.to_candidate(), &app.dependencies[0]), + "plain dependency ('Python', '3.12.3') must still reject -bare" + ); +} + +#[test] +fn list_append_accepts_trailing_comma() { + let src = "\ +name = 'Extrae' +version = '4.2.0' +toolchain = {'name': 'gompi', 'version': '2023b'} +builddependencies = [('Automake', '1.16.5')] +dependencies = [('zlib', '1.2.13')] +if ARCH != 'aarch64': + dependencies.append( + ('libunwind', '1.6.2'), + ) +builddependencies.append(('CMake', '3.27.6'),) +"; + let parsed = resolve_easyconfig_str_for_arch(src, "x86_64").expect("parse Extrae"); + let dep_names: Vec<&str> = parsed + .dependencies + .iter() + .map(|d| d.name.as_str()) + .collect(); + let bdep_names: Vec<&str> = parsed + .builddependencies + .iter() + .map(|d| d.name.as_str()) + .collect(); + assert_eq!(dep_names, vec!["zlib", "libunwind"]); + assert_eq!(bdep_names, vec!["Automake", "CMake"]); +} From 60f508a870eba223f0f3b27bdee29c1276667a78 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 05:45:07 +0000 Subject: [PATCH 5/9] fix(eb_parse): accept unparenthesized tuples on an unpacking RHS Collect comma-separated right-hand side expressions on the same logical line inside `finish_unpack` into a `Value::Tuple` instead of stopping after the first expression. Without comma collection, Python tuple-unpacking lines such as `_parallel_tests, _test_type = 1, 'fast'` failed with an integer error and left `_parallel_tests` undefined, causing four `CuPy` easyconfigs to drop their `exts_list`. --- .../+unpack-unparenthesized-tuple.bugfix.md | 1 + src/eb_parse.rs | 53 ++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 changelog.d/+unpack-unparenthesized-tuple.bugfix.md diff --git a/changelog.d/+unpack-unparenthesized-tuple.bugfix.md b/changelog.d/+unpack-unparenthesized-tuple.bugfix.md new file mode 100644 index 00000000..a9566103 --- /dev/null +++ b/changelog.d/+unpack-unparenthesized-tuple.bugfix.md @@ -0,0 +1 @@ +Parse unparenthesized comma-separated right-hand side tuples in `eb_parse` unpacking assignments (such as `_parallel_tests, _test_type = 1, 'fast'`) so `exts_list` in `CuPy` recipes is preserved. diff --git a/src/eb_parse.rs b/src/eb_parse.rs index b1141350..6cccdf01 100644 --- a/src/eb_parse.rs +++ b/src/eb_parse.rs @@ -826,7 +826,34 @@ impl<'a> Parser<'a> { if self.bump() != Some(b'=') { return Err(self.err("expected '=' in an unpacking assignment")); } - let value = self.parse_expr()?; + let first_val = self.parse_expr()?; + let before_ws = self.pos; + self.skip_ws(); + let crossed_line = self.src[before_ws..self.pos].contains(&b'\n'); + let value = if !crossed_line && self.peek() == Some(b',') { + let mut items = vec![first_val]; + while self.peek() == Some(b',') { + self.pos += 1; + let before_next = self.pos; + self.skip_ws(); + let next_crossed = self.src[before_next..self.pos].contains(&b'\n'); + if next_crossed || matches!(self.peek(), None | Some(b';')) { + self.pos = before_next; + break; + } + items.push(self.parse_expr()?); + let after_ws = self.pos; + self.skip_ws(); + if self.src[after_ws..self.pos].contains(&b'\n') { + self.pos = after_ws; + break; + } + } + Value::Tuple(items) + } else { + self.pos = before_ws; + first_val + }; let items = match value { Value::List(items) | Value::Tuple(items) => items, other => { @@ -7524,4 +7551,28 @@ mod hierarchy_universe_tests { assert_eq!(kept.len(), 1); assert_eq!(kept[0].name, "FlexiBLAS"); } + + #[test] + fn unpacking_accepts_unparenthesized_tuple_rhs() { + let src = "\ +easyblock = 'PythonBundle' +name = 'CuPy' +version = '13.6.0' +toolchain = {'name': 'foss', 'version': '2024a'} +_parallel_tests, _test_type = 1, 'fast' +exts_list = [ + ('fastrlock', '0.8.3', {}), + ('cupy', version, { + 'runtest': 'pytest -n %s tests -k \"%s\"' % (_parallel_tests, _test_type), + }), +] +"; + let (parsed, skipped) = resolve_easyconfig_str_reporting(src).expect("parse CuPy"); + assert!( + skipped.is_empty(), + "unexpected skipped statements: {skipped:?}" + ); + let exts: Vec<&str> = parsed.exts_list.iter().map(|e| e.name.as_str()).collect(); + assert_eq!(exts, vec!["fastrlock", "cupy"]); + } } From 3337e9186a24c7879321d1261fb3b091b027f731 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 05:47:06 +0000 Subject: [PATCH 6/9] fix(eb_parse): evaluate generator expressions in calls and parens Generalize `eval_list_comprehension` into `eval_comprehension` with a configurable closer byte and invoke it from `parse_method_call` and `parse_tuple_or_group` when a bracket-depth-zero `for` clause appears. Generator expressions inside `str.join(...)` calls caused seven `PythonBundle` easyconfigs (`AlphaPulldown` and the `jax` / `scib-metrics` bundles) to fail with unknown loop variables and drop their `exts_list` entries. --- .../+generator-expr-in-calls.bugfix.md | 1 + src/eb_parse.rs | 100 ++++++++++++++++-- 2 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 changelog.d/+generator-expr-in-calls.bugfix.md diff --git a/changelog.d/+generator-expr-in-calls.bugfix.md b/changelog.d/+generator-expr-in-calls.bugfix.md new file mode 100644 index 00000000..6dcc3336 --- /dev/null +++ b/changelog.d/+generator-expr-in-calls.bugfix.md @@ -0,0 +1 @@ +Evaluate single-clause generator expressions inside method call arguments and parentheses (`sep.join(expr for var in seq)`) in `eb_parse`, recovering dropped `exts_list` blocks in `AlphaPulldown`, `jax`, and `scib-metrics`. diff --git a/src/eb_parse.rs b/src/eb_parse.rs index 6cccdf01..22c3dcbf 100644 --- a/src/eb_parse.rs +++ b/src/eb_parse.rs @@ -935,6 +935,15 @@ impl<'a> Parser<'a> { self.pos += 1; break; } + if positional.is_empty() && keywords.is_empty() { + let elem_at = self.pos; + if let Some(for_at) = self.comprehension_for(elem_at) { + let gen = self.eval_comprehension(elem_at, for_at, b')')?; + positional.push(gen); + return call_method(&receiver, &name, &positional, &keywords) + .map_err(|e| self.err(e)); + } + } if let Some((key, value)) = self.parse_keyword_arg()? { saw_keyword = true; keywords.push((key, value)); @@ -1512,9 +1521,15 @@ impl<'a> Parser<'a> { prev_ok && next_ok } - /// `[expr for name in seq]`. The element is parsed once per item, after - /// the name is bound, because it refers to that name. - fn eval_list_comprehension(&mut self, elem_at: usize, for_at: usize) -> Result { + /// `[expr for name in seq]` or `(expr for name in seq)`. The element is + /// parsed once per item, after the name is bound, because it refers to that + /// name. + fn eval_comprehension( + &mut self, + elem_at: usize, + for_at: usize, + closer: u8, + ) -> Result { let depth = self.depth; self.pos = for_at; let kw = self.parse_ident()?; @@ -1532,8 +1547,11 @@ impl<'a> Parser<'a> { if self.keyword_at(self.pos, "if") { return Err(self.err("a comprehension filter is not read")); } - if self.bump() != Some(b']') { - return Err(self.err("a comprehension is not closed by ']'")); + if self.bump() != Some(closer) { + return Err(self.err(format!( + "a comprehension is not closed by '{}'", + closer as char + ))); } let end = self.pos; let items = match iterable { @@ -1573,7 +1591,7 @@ impl<'a> Parser<'a> { if self.peek() != Some(b']') { let elem_at = self.pos; if let Some(for_at) = self.comprehension_for(elem_at) { - return self.eval_list_comprehension(elem_at, for_at); + return self.eval_comprehension(elem_at, for_at, b']'); } } let mut items = Vec::new(); @@ -1617,6 +1635,10 @@ impl<'a> Parser<'a> { self.depth -= 1; return Ok(Value::Tuple(vec![])); } + let elem_at = self.pos; + if let Some(for_at) = self.comprehension_for(elem_at) { + return self.eval_comprehension(elem_at, for_at, b')'); + } let first = self.parse_expr()?; self.skip_ws(); if self.peek() == Some(b')') { @@ -7575,4 +7597,70 @@ exts_list = [ let exts: Vec<&str> = parsed.exts_list.iter().map(|e| e.name.as_str()).collect(); assert_eq!(exts, vec!["fastrlock", "cupy"]); } + + #[test] + fn generator_expressions_work_in_join_calls_and_parens() { + let alphapulldown = "\ +easyblock = 'PythonBundle' +name = 'AlphaPulldown' +version = '2.0.0' +toolchain = {'name': 'foss', 'version': '2023a'} +local_tests = ['custom_db', 'modelcif'] +local_testinstall_PATH = 'PATH=/tmp:$PATH' +exts_list = [ + ('contextlib2', '21.6.0', {}), + (name, version, { + 'runtest': '%s pytest -s %s ' % (local_testinstall_PATH, ' '.join('test/test_%s.py' % x for x in local_tests)), + }), +] +"; + let (ap, ap_skipped) = + resolve_easyconfig_str_reporting(alphapulldown).expect("AlphaPulldown"); + assert!( + ap_skipped.is_empty(), + "AlphaPulldown skipped: {ap_skipped:?}" + ); + assert_eq!( + ap.exts_list + .iter() + .map(|e| e.name.as_str()) + .collect::>(), + vec!["contextlib2", "AlphaPulldown"] + ); + + let jax_and_scib = "\ +easyblock = 'PythonBundle' +name = 'scib-metrics' +version = '0.5.9' +toolchain = {'name': 'foss', 'version': '2024a'} +_float64_tests_types = ['100-1000', '1000-100'] +_float64_tests_list = [ + f'tests/utils/test_pca.py::test_pca[{x}]' + for x in _float64_tests_types +] +_float64_tests = ' '.join(x for x in _float64_tests_list) +_deselected_tests = ' '.join( + f'--deselect {x}' + for x in _float64_tests_list +) +local_test_cmd = ' '.join((f'{item}!' for item in _float64_tests_types)) + ' && ' + _deselected_tests + ' && ' + _float64_tests +exts_list = [ + ('harmonypy', '0.1.0', {}), + (name, version, {'runtest': local_test_cmd}), +] +"; + let (sm, sm_skipped) = + resolve_easyconfig_str_reporting(jax_and_scib).expect("scib-metrics"); + assert!( + sm_skipped.is_empty(), + "scib-metrics skipped: {sm_skipped:?}" + ); + assert_eq!( + sm.exts_list + .iter() + .map(|e| e.name.as_str()) + .collect::>(), + vec!["harmonypy", "scib-metrics"] + ); + } } From ed8af52d951e9eba235c92561f787a17d9a4d4f9 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 05:49:06 +0000 Subject: [PATCH 7/9] fix(hierarchy): preserve CUDA versionsuffix on nvidia-compilers level Append the dependency `versionsuffix` when `derive_nvidia_family_hierarchy` reads the `nvidia-compilers` or `NVHPC` pin from an `NVHPC` definition. Without the suffix, `NVHPC-25.3-CUDA-12.8.0` emitted `nvidia-compilers-25.3` rather than `nvidia-compilers-25.3-CUDA-12.8.0`. That broke dependency lookup and build order for `QuantumESPRESSO` (`libxc`) and `Tinker-HP` (`GSL`). --- ...+nvidia-compilers-cuda-hierarchy.bugfix.md | 1 + src/hierarchy.rs | 82 ++++++++++++++++--- 2 files changed, 73 insertions(+), 10 deletions(-) create mode 100644 changelog.d/+nvidia-compilers-cuda-hierarchy.bugfix.md diff --git a/changelog.d/+nvidia-compilers-cuda-hierarchy.bugfix.md b/changelog.d/+nvidia-compilers-cuda-hierarchy.bugfix.md new file mode 100644 index 00000000..9cf3eb15 --- /dev/null +++ b/changelog.d/+nvidia-compilers-cuda-hierarchy.bugfix.md @@ -0,0 +1 @@ +Include `versionsuffix` when reading the `nvidia-compilers` or `NVHPC` dependency pin inside `derive_nvidia_family_hierarchy`, so `NVHPC-25.3-CUDA-12.8.0` hierarchies emit `nvidia-compilers-25.3-CUDA-12.8.0` and resolve `libxc` and `GSL` dependencies built against it. diff --git a/src/hierarchy.rs b/src/hierarchy.rs index 63b1a50c..df4e12f6 100644 --- a/src/hierarchy.rs +++ b/src/hierarchy.rs @@ -912,16 +912,16 @@ fn derive_nvidia_family_hierarchy( // deprecated spelling, still what older generations in the wild carry. Accept // either, preferring the current one, or a correctly-built new generation // reads as an unknown hierarchy. - let nvhpc_ver = ["nvidia-compilers", "NVHPC"] - .iter() - .find_map(|compiler| { - def.dependencies - .iter() - .chain(def.builddependencies.iter()) - .find(|d| d.name == *compiler) - .and_then(|d| exact_pin_version(&d.version_req)) - })? - .to_string(); + let nvhpc_ver = ["nvidia-compilers", "NVHPC"].iter().find_map(|compiler| { + def.dependencies + .iter() + .chain(def.builddependencies.iter()) + .find(|d| d.name == *compiler) + .and_then(|d| { + exact_pin_version(&d.version_req) + .map(|v| format!("{v}{}", d.versionsuffix.as_deref().unwrap_or_default())) + }) + })?; let mut members = vec![Toolchain { name: "system".into(), @@ -2605,4 +2605,66 @@ mod tests { ); assert!(hierarchy_member_rank(&h, &gcc14).is_none()); } + + #[test] + fn nvhpc_cuda_hierarchy_preserves_nvidia_compilers_cuda_suffix() { + let nvhpc = crate::resolve_easyconfig_str( + "name = 'NVHPC'\n\ + version = '25.3'\n\ + versionsuffix = '-CUDA-%(cudaver)s'\n\ + toolchain = SYSTEM\n\ + dependencies = [('CUDA', '12.8.0'), ('nvidia-compilers', version, versionsuffix)]\n", + ) + .expect("NVHPC") + .to_candidate(); + let nvc = crate::resolve_easyconfig_str( + "name = 'nvidia-compilers'\n\ + version = '25.3'\n\ + versionsuffix = '-CUDA-%(cudaver)s'\n\ + toolchain = SYSTEM\n\ + dependencies = [('CUDA', '12.8.0'), ('GCCcore', '14.2.0')]\n", + ) + .expect("nvidia-compilers") + .to_candidate(); + let libxc = crate::resolve_easyconfig_str( + "name = 'libxc'\n\ + version = '7.0.0'\n\ + toolchain = {'name': 'nvidia-compilers', 'version': '25.3-CUDA-12.8.0'}\n", + ) + .expect("libxc") + .to_candidate(); + let qe = crate::resolve_easyconfig_str( + "name = 'QuantumESPRESSO'\n\ + version = '7.5'\n\ + toolchain = {'name': 'NVHPC', 'version': '25.3-CUDA-12.8.0'}\n\ + dependencies = [('libxc', '7.0.0')]\n", + ) + .expect("QuantumESPRESSO"); + let qe_cand = qe.to_candidate(); + let cuda = cand("CUDA", "12.8.0", "system", "", None); + let gcccore = cand("GCCcore", "14.2.0", "system", "", None); + let universe = vec![nvhpc, nvc, libxc, qe_cand, cuda, gcccore]; + + let h = hierarchy_for_with_tree(&qe.toolchain, None, &universe).expect("hierarchy"); + let labels: Vec = h.members.iter().map(Toolchain::label).collect(); + assert!( + labels.iter().any(|l| l == "nvidia-compilers-25.3-CUDA-12.8.0"), + "NVHPC-25.3-CUDA-12.8.0 hierarchy must carry nvidia-compilers-25.3-CUDA-12.8.0, got {labels:?}" + ); + + let dep_check = crate::check_recipe_deps(&qe, &universe); + assert!( + dep_check.ok(), + "QuantumESPRESSO -> libxc must resolve via nvidia-compilers-25.3-CUDA-12.8.0: {:?}", + dep_check.missing + ); + + let order = crate::build_order::build_order( + &universe, + &["QuantumESPRESSO".into()], + crate::build_order::Choice::Newest, + ) + .expect("build_order must include libxc"); + assert!(order.iter().any(|c| c.name == "libxc")); + } } From 356c92695d9c85e7ccd4be12515fcf45e296b875 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 06:18:34 +0000 Subject: [PATCH 8/9] fix(build_order): enforce dependency toolchain over system module match Restrict the exact module_version shortcut inside `satisfies` so it only applies when no non-system dependency toolchain override is specified. Without that guard, a `SYSTEM` toolchain recipe declaring an explicit dependency toolchain, such as `('binutils', '2.38', '', ('GCCcore', '11.3.0'))`, matched the `SYSTEM` variant `binutils/2.38` before reaching the toolchain check. --- .../+satisfies-dep-toolchain.bugfix.md | 3 + src/build_order.rs | 69 ++++++++++++++++++- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 changelog.d/+satisfies-dep-toolchain.bugfix.md diff --git a/changelog.d/+satisfies-dep-toolchain.bugfix.md b/changelog.d/+satisfies-dep-toolchain.bugfix.md new file mode 100644 index 00000000..bd538617 --- /dev/null +++ b/changelog.d/+satisfies-dep-toolchain.bugfix.md @@ -0,0 +1,3 @@ +Enforce non-system per-dependency toolchain overrides in +`build_order::satisfies` even when a `SYSTEM` variant shares the exact +module version string. diff --git a/src/build_order.rs b/src/build_order.rs index 96e2a8b2..26a2ab97 100644 --- a/src/build_order.rs +++ b/src/build_order.rs @@ -448,7 +448,15 @@ pub(crate) fn satisfies(candidate: &Candidate, dep: &DepReq) -> bool { // is string equality rather than a relaxed match. if let Some(pinned) = dep.version_req.strip_prefix("==") { let wanted = format!("{pinned}{}", dep.versionsuffix.as_deref().unwrap_or("")); - if module_version(candidate) == wanted { + let toolchain_ok = match dep.toolchain.as_ref() { + None => true, + Some(want) => { + crate::hierarchy::toolchains_match(&candidate.toolchain, want) + || (crate::hierarchy::is_system_toolchain(want) + && dep.versionsuffix.as_deref().is_some_and(|s| !s.is_empty())) + } + }; + if toolchain_ok && module_version(candidate) == wanted { return true; } } @@ -2338,4 +2346,63 @@ mod tests { assert!(names(&plain).iter().any(|name| name.starts_with("Base-"))); assert!(names(&plain).iter().any(|name| name.starts_with("Mid-"))); } + + #[test] + fn satisfies_honors_explicit_toolchain_when_system_variant_shares_version() { + let binutils_system = Candidate { + name: "binutils".into(), + version: "2.38".into(), + toolchain: tc("system", "system"), + versionsuffix: None, + versionprefix: None, + easyconfig_path: String::new(), + dependencies: vec![], + builddependencies: vec![], + exts_list: vec![], + easyblock: None, + moduleclass: None, + }; + let binutils_gcccore = Candidate { + name: "binutils".into(), + version: "2.38".into(), + toolchain: tc("GCCcore", "11.3.0"), + versionsuffix: None, + versionprefix: None, + easyconfig_path: String::new(), + dependencies: vec![], + builddependencies: vec![], + exts_list: vec![], + easyblock: None, + moduleclass: None, + }; + let dep = DepReq { + name: "binutils".into(), + version_req: "==2.38".into(), + versionsuffix: Some(String::new()), + toolchain: Some(tc("GCCcore", "11.3.0")), + }; + assert!(!satisfies(&binutils_system, &dep)); + assert!(satisfies(&binutils_gcccore, &dep)); + + let system_suffixed = Candidate { + name: "cuQuantum".into(), + version: "25.03.0.11".into(), + toolchain: tc("system", "system"), + versionsuffix: Some("-CUDA-12.6.0".into()), + versionprefix: None, + easyconfig_path: String::new(), + dependencies: vec![], + builddependencies: vec![], + exts_list: vec![], + easyblock: None, + moduleclass: None, + }; + let system_dep = DepReq { + name: "cuQuantum".into(), + version_req: "==25.03.0.11-CUDA-12.6.0".into(), + versionsuffix: Some(String::new()), + toolchain: Some(tc("system", "system")), + }; + assert!(satisfies(&system_suffixed, &system_dep)); + } } From dd061b27eeed693007994af4ba74fdc82083075e Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Fri, 20 Nov 2026 06:09:01 +0000 Subject: [PATCH 9/9] fix(eb_parse): map EasyBuild alternative parameter names Normalize EasyBuild's documented alternative parameter spellings such as `version_suffix`, `version_prefix`, `deps`, and `build_deps` onto their canonical parameter names right after parsing an easyconfig. Recipes such as `R-crumble-0.1.2-foss-2023b-R-4.4.1.eb` declare `version_suffix`, the alias EasyBuild accepts. That left `versionsuffix` unset and dropped the suffix from the module name. --- .../+eb-parse-alt-param-names.bugfix.md | 3 + src/eb_parse.rs | 78 ++++++++++++++++--- 2 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 changelog.d/+eb-parse-alt-param-names.bugfix.md diff --git a/changelog.d/+eb-parse-alt-param-names.bugfix.md b/changelog.d/+eb-parse-alt-param-names.bugfix.md new file mode 100644 index 00000000..28c0b216 --- /dev/null +++ b/changelog.d/+eb-parse-alt-param-names.bugfix.md @@ -0,0 +1,3 @@ +Map EasyBuild's alternative easyconfig parameter spellings such as +`version_suffix`, `version_prefix`, `deps`, and `build_deps` to their +canonical parameter names after parsing. diff --git a/src/eb_parse.rs b/src/eb_parse.rs index 22c3dcbf..ee46628f 100644 --- a/src/eb_parse.rs +++ b/src/eb_parse.rs @@ -2605,18 +2605,49 @@ fn value_to_dep(val: &Value, arch: &str) -> Result { /// Column zero and an `=` that is not `==`, which is what a top-level /// easyconfig assignment looks like. Augmented assignment counts: a recipe /// that appends to a dependency list still has one. +const ALTERNATIVE_PARAM_NAMES: &[(&str, &str)] = &[ + ("build_deps", "builddependencies"), + ("configure_opts", "configopts"), + ("deps", "dependencies"), + ("env_mod_category", "moduleclass"), + ("exts_class_map", "exts_classmap"), + ("exts_default_class", "exts_defaultclass"), + ("exts_default_opts", "exts_default_options"), + ("hidden_deps", "hiddendependencies"), + ("version_prefix", "versionprefix"), + ("version_suffix", "versionsuffix"), +]; + +fn normalize_alternative_param_names(env: &mut HashMap) { + for &(alt, canonical) in ALTERNATIVE_PARAM_NAMES { + if !env.contains_key(canonical) { + if let Some(value) = env.get(alt).cloned() { + env.insert(canonical.to_string(), value); + } + } + } +} + fn assigns_at_top_level(src: &str, field: &str) -> bool { - src.lines().any(|line| { - let Some(rest) = line.strip_prefix(field) else { - return false; - }; - let rest = rest.trim_start(); - match rest.as_bytes() { - [b'=', b'=', ..] => false, - [b'=', ..] => true, - [b'+', b'=', ..] => true, - _ => false, + let mut names = vec![field]; + for &(alt, canonical) in ALTERNATIVE_PARAM_NAMES { + if canonical == field { + names.push(alt); } + } + src.lines().any(|line| { + names.iter().any(|name| { + let Some(rest) = line.strip_prefix(name) else { + return false; + }; + let rest = rest.trim_start(); + match rest.as_bytes() { + [b'=', b'=', ..] => false, + [b'=', ..] => true, + [b'+', b'=', ..] => true, + _ => false, + } + }) }) } @@ -2909,6 +2940,7 @@ fn resolve_easyconfig_str_inner(src: &str, arch: &str) -> Result".into(), e))?; + normalize_alternative_param_names(&mut parser.env); let name = parser .env @@ -7663,4 +7695,30 @@ exts_list = [ vec!["harmonypy", "scib-metrics"] ); } + + #[test] + fn alternative_easyconfig_parameter_names_populate_canonical_fields() { + let src = "\ +easyblock = 'Bundle' +name = 'R-crumble' +version = '0.1.2' +version_suffix = '-R-%(rver)s' +version_prefix = 'alt-' +toolchain = {'name': 'foss', 'version': '2023b'} +deps = [('R', '4.4.1')] +build_deps = [('CMake', '3.27.6')] +configure_opts = '--with-pic' +env_mod_category = 'tools' +"; + let (parsed, skipped) = resolve_easyconfig_str_reporting(src).expect("parse"); + assert!(skipped.is_empty(), "unexpected skipped: {skipped:?}"); + assert_eq!(parsed.versionsuffix.as_deref(), Some("-R-4.4.1")); + assert_eq!(parsed.versionprefix.as_deref(), Some("alt-")); + assert_eq!(parsed.dependencies.len(), 1); + assert_eq!(parsed.dependencies[0].name, "R"); + assert_eq!(parsed.builddependencies.len(), 1); + assert_eq!(parsed.builddependencies[0].name, "CMake"); + assert_eq!(parsed.configopts.as_deref(), Some("--with-pic")); + assert_eq!(parsed.moduleclass.as_deref(), Some("tools")); + } }