feat(spur-cli): honor SRUN_/SALLOC_/SLURM_ env-var defaults for srun …#421
Merged
Conversation
…and salloc Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds Slurm-compatible environment-variable defaulting for srun/salloc (with SPUR_* native twins and CLI precedence), and updates --gres parsing to match Slurm’s comma-splitting + last-wins behavior.
Changes:
- Introduces
env_defaults.rshelpers to apply ordered env-var aliases only when a flag wasn’t set on the CLI (viaArgMatches::value_source). - Updates
srunandsallocto parse intoArgMatches, then apply env defaults post-parse. - Fixes
--gresto split comma-lists and make repeated--gresreplace previous values (last wins).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/spur-cli/src/srun.rs | Switches to matches-based parsing, applies env defaults, and updates --gres parsing semantics. |
| crates/spur-cli/src/salloc.rs | Switches to matches-based parsing, applies env defaults, and updates --gres parsing semantics. |
| crates/spur-cli/src/main.rs | Registers the new shared env-defaults module. |
| crates/spur-cli/src/env_defaults.rs | Adds shared env resolution helpers and env-isolation test guard + unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #421 +/- ##
==========================================
+ Coverage 70.86% 71.21% +0.34%
==========================================
Files 140 141 +1
Lines 41849 42390 +541
==========================================
+ Hits 29656 30185 +529
- Misses 12193 12205 +12 🚀 New features to boost your workflow:
|
…env-var values Co-authored-by: Cursor <cursoragent@cursor.com>
shiv-tyagi
reviewed
Jul 14, 2026
shiv-tyagi
approved these changes
Jul 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…and salloc
Summary
Adds environment-variable defaults for
srunandsalloc, aligning Spur with Slurm's precedence model (closes #279). Also fixes--gresCLI parsing to match Slurm semantics.Precedence for every affected flag is now: CLI arg >
SPUR_*native twin >SLURM_*/SRUN_*/SALLOC_*> built-in default.What changed
env_defaults.rs) —apply_str/apply_string/apply_flag/apply_csvresolve multi-alias env vars with correct CLI precedence, detected viaArgMatches::value_source. Includes a sharedEnvGuardtest fixture and unit tests.srun— parses intoArgMatches, then appliesSLURM_*(plus genuineSRUN_*where Slurm uses them) andSPUR_*twins as defaults. This letssruninside an allocation inheritSLURM_NTASKS/SLURM_CPUS_PER_TASK/SLURM_NNODES, so a step sizes to the allocation instead of the bare-n1 -c1defaults.salloc— same pattern forSALLOC_*/SPUR_*. Stays Slurm-faithful:--nodes,--ntasks,--cpus-per-task, and--job-namehave no env var in real Slurm, so Spur ignores them too.--gresfix (srun+salloc) — addedvalue_delimiter = ','+overrides_with = "gres"so a comma-list (--gres=gpu:1,fpga:2) expands to multiple GRES and a repeated--gresreplaces (last wins), matching Slurm and Spur's ownsbatch. Previously the CLI kept comma-lists as one un-parseable element and accumulated repeated flags.Design notes
#[arg(env=...)]supports only one env var per flag, so multi-alias resolution is done in a post-parse step keyed offvalue_source(keeps CLI-set detection accurate even withoverrides_with).serial_test) and useEnvGuard, which clears allSPUR_/SLURM_/SALLOC_/SRUN_-prefixed vars on construction/drop, keeping them independent of the runner's environment and of each other.Testing
cargo clippy -p spur-cli --all-targets— clean.cargo test -p spur-cli— all 151 tests pass (new unit tests cover defaults, CLI override, alias precedence, numeric/bool/CSV parsing, gres comma-split, and last-wins).salloc:SALLOC_PARTITIONenv default applied; CLI-poverrides it.srun:SLURM_NTASKSenv default applied to submitted job; CLI-noverrides it;SPUR_NTASKStakes precedence over theSLURM_NTASKStwin.Known gap / follow-up
sbatch still resolves env defaults via clap's single SBATCH_* attribute per flag and does not yet honor SPUR_* twins (e.g. SPUR_PARTITION), unlike srun/salloc. Unifying sbatch onto env_defaults is deferred to a follow-up PR since it must preserve sbatch's CLI > env > #SBATCH directive precedence.